Split string into an array on spaces
$string = "The quick brown fox jumps over the lazy dog." $string.split()
Exclude blanks when splitting a string into an array
$option = [System.StringSplitOptions]::RemoveEmptyEntries $string.split(";",$option)
Get all Text after a character
$string = "1. Computer name:DC-G11-FTW.contoso.com" $string.Substring($string.IndexOf(":")+1,$string.length-$string.IndexOf(":")-1)
Get all Text before a character
$string = "[email protected]" $string.Substring(0,$string.IndexOf("@"))
Remove all special characters including spaces
$string = "1. Computer name:DC-G11-FTW.contoso.com" [regex]::Replace($string,"[^0-9a-zA-Z]","")
Remove all special characters leaving spaces
$string = "1. Computer name:DC-G11-FTW.contoso.com" [regex]::Replace($string,"[^0-9a-zA-Z ]","")
Replace using Regular Expression
$string = 'Thank you for calling 555-5757 your order total is $123.32' $string -Replace "[0-9]","0"
Replace using plain text replacement
$string = 'The quick brown fox jumps over the lazy dog' $string.Replace("brown","red")