Export (0) Print
Expand All
Expand Minimize

Converting VBScript's Left Function


Windows PowerShell


Definition: Returns a specified number of characters from the left side of a string.

Left

What’s that? You want to know if it’s possible to use Windows PowerShell to return the first x characters in a string? Of course it is: all you have to do is call the Substring method, passing two parameters: the starting character (with 0 being the first character position) and the number of characters to return. For example, this command assigns the letters of the alphabet to a variable named $a, then uses Substring to reassign $a just the first three letters in the string:



$a="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$a = $a.substring(0,3)

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



ABC


Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft