语言

Strings.Asc 方法

定义

返回一个整数值,表示对应于字符的字符代码。

重载

名称 说明
Asc(Char)

返回一个整数值,表示对应于字符的字符代码。

Asc(String)

返回一个整数值,表示对应于字符的字符代码。

Asc(Char)

Source:
Strings.vb
Source:
Strings.vb
Source:
Strings.vb
Source:
Strings.vb
Source:
Strings.vb

返回一个整数值,表示对应于字符的字符代码。

public:
 static int Asc(char String);
public static int Asc(char String);
static member Asc : char -> int
Public Function Asc (String As Char) As Integer

参数

String
Char

必填。 任何有效 Char 或 String 表达式。 如果 String 为 String 表达式,则只使用字符串的第一个字符进行输入。 如果 String 为 Nothing 或不包含任何字符, ArgumentException 则会发生错误。

返回

对应于字符的字符代码。

示例

以下示例使用 Asc 函数返回 Integer 对应于每个字符串中的第一个字母的字符代码。

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

注解

Asc 返回输入字符 的代码点或字符代码。 对于单字节字符集(SBCS)值,这可以是 0 到 255,对于双字节字符集(DBCS)值,-32768 到 32767。

AscW 返回输入字符的 Unicode 代码点。 这可以是 0 到 65535。 返回的值独立于当前线程的区域性和代码页设置。

注释

早期版本的 Visual Basic 的 AscB 函数返回字节的代码,而不是字符。 它主要用于转换双字节字符集 (DBCS) 应用程序中的字符串。 所有 Visual Basic 2005 字符串都位于 Unicode 中,不再支持 AscB。

另请参阅

适用于

Asc(String)

Source:
Strings.vb
Source:
Strings.vb
Source:
Strings.vb
Source:
Strings.vb
Source:
Strings.vb

返回一个整数值,表示对应于字符的字符代码。

public:
 static int Asc(System::String ^ String);
public static int Asc(string String);
static member Asc : string -> int
Public Function Asc (String As String) As Integer

参数

String
String

必填。 任何有效 Char 或 String 表达式。 如果 String 为 String 表达式,则只使用字符串的第一个字符进行输入。 如果 String 为 Nothing 或不包含任何字符, ArgumentException 则会发生错误。

返回

对应于字符的字符代码。

示例

以下示例使用 Asc 函数返回 Integer 对应于每个字符串中的第一个字母的字符代码。

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

注解

Asc 返回输入字符 的代码点或字符代码。 对于单字节字符集(SBCS)值,这可以是 0 到 255,对于双字节字符集(DBCS)值,-32768 到 32767。

AscW 返回输入字符的 Unicode 代码点。 这可以是 0 到 65535。 返回的值独立于当前线程的区域性和代码页设置。

注释

早期版本的 Visual Basic 的 AscB 函数返回字节的代码,而不是字符。 它主要用于转换双字节字符集 (DBCS) 应用程序中的字符串。 所有 Visual Basic 2005 字符串都位于 Unicode 中,不再支持 AscB。

另请参阅

适用于