Split Special Characters

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

PowerShell’s new –split operator can split text into parts. Usually, you will submit a delimiter character to tell –split where to split:

PS> "1,2,3,4" -split ","
1
2
3
4

However, you can also submit a script block and calculate where to split. If you take advantage of the many specific character tests available in the [Char] type, you can then split based on punctuation or other character groups:

"Hello, this is a test" -split { [Char]::isPunctuation($_) }

Use this line to view all available character groups:

[char] | Get-Member -Static -MemberType Method -Name is*
[Char]::isPunctuation

 

Twitter This Tip! ReTweet this Tip!


Posted Mar 30 2011, 08:00 AM by ps1
Copyright 2012 PowerShell.com. All rights reserved.