PowerTip: Remove Leading and Trailing Spaces with PowerShell

Doctor Scripto

Summary: Use the Trim() method to remove extraneous space from a String object.

Hey, Scripting Guy! Question Is there an easy way to drop all spaces that are before or after a string in Windows PowerShell?

Hey, Scripting Guy! Answer Use the Trim() method to remove all spaces before and after a string from the output, for example:

$Something='                 I love PowerShell                     '



Discussion is closed.

Feedback usabilla icon