Converting VBScript's LTrim Function

Definition: Returns a copy of a string without leading spaces.


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

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

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


Return to the VBScript to Windows PowerShell home page