Return to Snippet

Revision: 13466
at April 24, 2009 17:24 by ericmorin21


Initial Code
$badString = "This        is         not        the way   it   should     be."
$badString #for debug only
while ($badString.Contains("  ")){
	$badString = $badString -replace "  "," "
	}
$badString

Initial URL


Initial Description
I needed to clean up strings with an unpredictable number of spaces interspersed throughout. Powershell's Replace method to the rescue.

Initial Title
Powershell - Replace multiple spaces with single spaces

Initial Tags
replace

Initial Language
Windows PowerShell