Monthly Archives: October 2013

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 :

http://technet.microsoft.com/en-us/library/hh847811.aspx

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

http://msdn.microsoft.com/en-us/library/vstudio/ms228388.aspx

OK so without any further  ado :

you can chain .Split in PowerShell like this :

$splittedRow = "<tag id='abcd' id2="efgh"></tag>".Split("""").Split("'")
Write-Host $splittedRow

This will return string splitted with delimiter ” and ‘.

Enjoy.