Powershell - Replace multiple spaces with single spaces


/ Published in: Windows PowerShell
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. $badString = "This is not the way it should be."
  2. $badString #for debug only
  3. while ($badString.Contains(" ")){
  4. $badString = $badString -replace " "," "
  5. }
  6. $badString

Report this snippet


Comments


You need to login to view comments.