Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all articles
Browse latest Browse all 3333

PowerTip: Remove Spaces from Both Ends of String

$
0
0

Summary: Learn to use Windows PowerShell to remove spaces from both ends of a string.

Hey, Scripting Guy! Question How can I use Windows PowerShell to remove spaces at both ends of a string?

Hey, Scripting Guy! Answer Use the Trim method from the System.String .NET Framework class. 
          In this example, I create a string with a space at each end of the word, then
          I call the Trim method to remove both spaces:

$string = " a String "

$string.Trim()

Note  The Trim method exists on strings, so to use it, simply call it directly from the string. 


Viewing all articles
Browse latest Browse all 3333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>