How to split string by string in Powershell

后端 未结 5 1187
既然无缘
既然无缘 2020-12-03 16:49

I\'m trying to spit the string with a delimiter, which is a string:

$string = \"5637144576, messag<>est<<>>5637145326, 1<<>>563         


        
5条回答
  •  醉话见心
    2020-12-03 17:34

    Sometimes PowerShell looks exactly like C# and at others, well you know...

    It could also be used thus:

    # A dummy text file
    $text = @'
    abc=3135066977,8701416400
    
    def=8763026853,6433607660
    
    xyz=3135066977,9878763344
    '@ -split [Environment]::NewLine,[StringSplitOptions]"RemoveEmptyEntries"
    
    "`nBefore `n------`n"
    
    $text
    
    "`nAfter `n-----`n"
    
    # Do whatever with this
    foreach ($line in $text)
    {
        $line.Replace("3135066977","6660985845")
    }
    

提交回复
热议问题