Ascii (character) Number
|character||String||Character to return as an ASCII code|
|Function result||Number||ASCII code for the character|
The Ascii command returns the ASCII code of character.
If there is more than one character in the string, Ascii returns the code of the first character.
The Char function is the counterpart of Ascii. It returns the character that an ASCII code represents.
Important: Within 4D, all the text values, fields, or variables that you have not yet converted to another ASCII map are Mac OS-encoded on both Macintosh and Windows. For more information, see the section ASCII Codes.
1. Uppercase and lowercase characters are considered equal within a comparison. You can use Ascii to differentiate between uppercase and lowercase characters. Thus, this line returns True:
("A" = "a")
On the other hand, this line returns False:
2. This example returns the ASCII value of the first character of the string "ABC":
vlAscii:=Ascii("ABC") ` vlAscii gets 65, the ASCII code of A
3. The following example tests for carriage returns and tabs:
For($vlChar;1;Length(vtText)) Case of : (vtText[[$vlChar]]=Char(Carriage return)) ` Do something : (vtText[[$vlChar]]=Char(Tab)) ` Do something else : (...) ` ... End case End for
When executed multiple times on large texts, this test will run faster when compiled if it is written this way:
For($vlChar;1;Length(vtText)) $vlAscii:=Ascii(vtText[[$vlChar]]) Case of : ($vlAscii=Carriage return) ` Do something : ($vlAscii=Tab) ` Do something else : (...) ` ... End case End for
The second piece of code runs faster for two reasons: it does only one character reference by iteration and uses LongInt comparisons instead of string comparisons to test for carriage returns and tabs. Use this technique when working with common ASCII codes such as CR and TAB.
ASCII Codes, Char, Character Reference Symbols.