Converting VBScript's Asc Function

Definition: Returns the ANSI character code corresponding to the first letter in a string.


It’s surprising how often scripters need to convert a character value (such as the letter A) to its ASCII equivalent (65). In Windows PowerShell you can determine the ASCII value of a character by using this crazy-looking line of code (which takes the character value of the letter A and then converts the result to a byte value):

$a = [byte][char] "A"

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