Suppose you have a variable and you want to remove all unwanted characters from it – for example commas.
In PowerShell, this is as easy as:
PS C:\> 'a,,b,c,d,' -replace ',' abcd
To remove multiple unwanted characters, simply chain more -replace operators on the end (note that some characters must be escaped, as we are using a regex the escape character is a backslash):
PS C:\> '.a,a\b,b\c,b\d\,d.\' -replace ',' -replace '\\' -replace '\.' aabbcbdd
Recent Comments