How to split string in PowerShell with multiple delimiters

Hello world.

I just wanted to share with you one simple stupid snippet (please note, I am PowerShell newbie so have mercy and if there is any better way, please share in comments, thank you).

Because in my current work we need to parse and update some .aspx files (I will try to publish this later on my github),  I am fiddling a bit with PowerShell and Regex and such stuff.

I wanted to split a row in processed .aspx file and I wanted to use multiple delimiters while splitting. But according to this :

you can’t use multiple delimiters as parameter, like say array of delimiters like I was used to in C# :

OK so without any further  ado :

you can chain .Split in PowerShell like this :

[powershell]$splittedRow = "<tag id=’abcd’ id2="efgh"></tag>".Split("""").Split("’")
Write-Host $splittedRow[/powershell]

This will return string splitted with delimiter ” and ‘.



This site uses Akismet to reduce spam. Learn how your comment data is processed.