AscW - VBScript


The AscW command in VB Script returns the ASCII code of the first Unicode character in a string. It is primarily used to determine the numerical representation of characters, especially in situations where character encodings are important, such as data parsing or string manipulation.




  • string: A string containing the Unicode character whose ASCII code is to be obtained.




1. Get ASCII code of a single character:

Dim char = "A"
Dim asciiCode = AscW(char)
Console.WriteLine(asciiCode) ' Output: 65

2. Get ASCII code of the first character in a string:

Dim str = "Hello World"
Dim asciiCode = AscW(str)
Console.WriteLine(asciiCode) ' Output: 72 (ASCII code of 'H')

Common Issues

  • Non-Unicode characters: AscW only works with Unicode characters. If the input string contains non-Unicode characters, an error will be thrown.
  • Empty string: If the input string is empty, AscW returns 0.


AscW can be used with other string manipulation functions in VB Script to perform advanced tasks, such as:

  • Character filtering: Filter a string based on the ASCII codes of its characters.
  • String encoding: Convert a string from one character encoding to another using the ASCII codes.
  • Data validation: Verify that a string contains only certain characters by checking their ASCII codes.
  • ChrW: Returns the Unicode character corresponding to a given ASCII code.
  • Mid: Extracts a substring from a string, which can be useful for processing individual characters.
  • Len: Returns the length of a string, helping determine the number of characters to process.