Name

asc — finds the ASCII value of a string character

Synopsis

int asc( str,  
  index);  
string   str;
int   index ;

Description

Returns the ASCII value of the first character of the string str, or, if the optional parameter index has been specified, the ASCII value of the character at position index (where the first character is at position zero). If str is a zero length string or index is out of range then the result is undefined, but is probably a run time error.

Example 30. asc Example

// Use asc to convert a string into a number
string str = "42";
int number = 0;

for(int i = 0; i < strlen(str); i++)
    number = number * 10 + (asc(str, i) - asc("0"));

print("The number is " + number);

See Also

This function complements the chr() function.