Converts the first character of a string to its ASCII integer value.
Asc ( string )
Argument |
Description |
---|---|
string |
The string for which you want the ASCII value of the first character |
Integer. Returns the ASCII value of the first character in string. If string is null, Asc returns null.
You can use Asc to find out the case of a character by testing whether its ASCII value is within the appropriate range.
This statement returns 65, the ASCII value for uppercase A:
Asc("A")
This example checks if the first character of string ls_name is uppercase:
String ls_name
IF Asc(ls_name) > 64 and Asc(ls_name) < 91 THEN ...
This example is a function that converts an array of integers into a string. Each integer specifies two characters. Its low byte is the first character in the pair and the high byte (ASCII * 256) is the second character. The function has an argument (iarr) which is the integer array:
string str_from_int, hold_str
integer arraylen
arraylen = UpperBound(iarr)
FOR i = 1 to arraylen
// Convert first character of pair to a char
hold_str = Char(iarr[i])
// Add characters to string after converting
// the integer's high byte to char
str_from_int = &
str_from_int + hold_str + &
Char((iarr[i] - Asc(hold_str)) / 256)
NEXT
For sample code that builds the integer array from a string, see Mid.