Strings.Asc 方法

定義

傳回整數值,以代表某字元的對應字元碼。

多載

Asc(Char)

傳回整數值,以代表某字元的對應字元碼。

Asc(String)

傳回整數值,以代表某字元的對應字元碼。

Asc(Char)

來源:
Strings.vb
來源:
Strings.vb
來源:
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

必要。 任何有效的 CharString 運算式。 如果 StringString 運算式,則只有字串的第一個字元才會用於輸入。 如果 StringNothing 或者不包含任何字元,則會發生 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 會傳回輸入字元的代碼 或字元碼。 對於單一位元組位元集,這可以是0到255, (SBCS) 值,而 -32768 到32767則為雙位元組字元集, (DBCS) 值。

AscW 會傳回輸入字元的 Unicode 字碼點。 這可以是 0 到 65535。 傳回的值與目前線程的文化特性和代碼頁設定無關。

注意

AscB舊版 Visual Basic 的函式會傳回位元組的程式代碼,而不是字元。 其主要用於在雙位元組字元集 (DBCS) 應用程式中轉換字串。 所有 Visual Basic 2005 字串都位於 Unicode 中,不再 AscB 支援。

另請參閱

適用於

Asc(String)

來源:
Strings.vb
來源:
Strings.vb
來源:
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

必要。 任何有效的 CharString 運算式。 如果 StringString 運算式,則只有字串的第一個字元才會用於輸入。 如果 StringNothing 或者不包含任何字元,則會發生 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 會傳回輸入字元的代碼 或字元碼。 對於單一位元組位元集,這可以是0到255, (SBCS) 值,而 -32768 到32767則為雙位元組字元集, (DBCS) 值。

AscW 會傳回輸入字元的 Unicode 字碼點。 這可以是 0 到 65535。 傳回的值與目前線程的文化特性和代碼頁設定無關。

注意

AscB舊版 Visual Basic 的函式會傳回位元組的程式代碼,而不是字元。 其主要用於在雙位元組字元集 (DBCS) 應用程式中轉換字串。 所有 Visual Basic 2005 字串都位於 Unicode 中,不再 AscB 支援。

另請參閱

適用於