Export (0) Print
Expand All
Expand Minimize
4 out of 6 rated this helpful - Rate this topic

Converting VBScript's Trim Function


Windows PowerShell


Definition: Returns a copy of a string without both leading and trailing spaces.

Trim

You had to know that this one was coming: In VBScript the Trim function is used to remove any blank spaces that appear at the beginning or the end of a string; in Windows PowerShell, you can carry out this same task by using the Trim() method. For example, these two commands assign a string value to the variable $a, then use the Trim() method to remove the blank spaces from both the beginning and the end of the string (note that, for illustration purposes, we’ve used dots to represent blank spaces):


$a = "..........123456789.........." 
$a = $a.Trim()

When you run this command and then echo back the value of $a you should get the following:


123456789


Return to the VBScript to Windows PowerShell home page

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.