/ Published in: Windows PowerShell
I needed to clean up strings with an unpredictable number of spaces interspersed throughout. Powershell's Replace method to the rescue.
Expand |
Embed | Plain Text
$badString = "This is not the way it should be." $badString #for debug only while ($badString.Contains(" ")){ $badString = $badString -replace " "," " } $badString
Comments
Subscribe to comments
You need to login to post a comment.

Maybe a regular expression might be help.
$string = "This is a string with lots of extraneous spaces." $string -replace '\s+', " "
The \s represents a whitespace character (space or tab) and the plus sign means one or more instances.
Just a thought.