Export (0) Print
Expand All

Strings.Asc Method (Char)

Returns an Integer value representing the character code corresponding to a character.

Namespace: Microsoft.VisualBasic
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public static int Asc (
	char String
)
public static int Asc (
	char String
)
public static function Asc (
	String : char
) : int
Not applicable.

Parameters

String

Required. Any valid Char or String expression. If String is a String expression, only the first character of the string is used for input. If String is Nothing or contains no characters, an ArgumentException error occurs.

Return Value

Returns an Integer value representing the character code corresponding to a character.

For more detailed information, see the Visual Basic topic Asc, AscW Functions.

Asc returns the code point, or character code, for the input character. This can be 0 through 255 for single-byte character set (SBCS) values and -32768 through 32767 for double-byte character set (DBCS) values.

The returned value depends on the code page for the current thread, which is contained in the ANSICodePage property of the TextInfo class in the System.Globalization namespace. You can obtain ANSICodePage by specifying System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage.

AscW returns the Unicode code point for the input character. This can be 0 through 65535. The returned value is independent of the culture and code page settings for the current thread.

NoteNote:

The AscB function of earlier versions of Visual Basic returns a code for a byte, rather than a character. It is used primarily for converting strings in double-byte character set (DBCS) applications. All Visual Basic 2005 strings are in Unicode, and AscB is no longer supported.

The following example uses the Asc function to return Integer Data Type (Visual Basic) character codes corresponding to the first letter in each string.

Dim codeInt As Integer
' The following line of code sets myInt to 65.
codeInt = Asc("A")
' The following line of code sets myInt to 97.
codeInt = Asc("a")
' The following line of code sets myInt to 65.
codeInt = Asc("Apple")

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft