Learn about Windows PowerShell
Summary: Easily split a string on multiple characters with Windows PowerShell.
How can I use Windows PowerShell to split a string that contains multiple separator characters (for example, a comma and a semicolon)?
Specify a string with the characters in it to the Split method:
PS C:\> $string = "This,is;a;string"
PS C:\> $string.Split(',;')
Didn't know that ... I generally just performed 2 splits.
Is there a way to split on double characters? eg., "This,;is,;a,;string" ?
Also didn't know that, also performed two splits... thanks!
This is a nice way to separate your Windows path into readable output:
$path = $env:path
@Ben, just put your double characters inside the quotes:
$string = "This,;is,;a,;string"
@Ben, the easiest way to do a multi-character delimiter is to use the -split operator.
Example: "This,is,;a;string" -split ',;'
What if the separator character is tick '? Are there any escape characters?
We can get output like 'This is a String' using the below code
'This;is,a;String'.Split(';,') -join ' '
@Chen V, that's a cool trick! Normally I would use -Replace multiple times, this really comes handy. Thanks!