StringTools
Char
map a number to the corresponding character
Ord
map a character to its ASCII code point
Calling Sequence
Parameters
Description
Examples
Char( n )
Ord( s )
n
-
integer in the range 0..255
s
Maple string
The procedures Char and Ord provide a bijective mapping between the characters that may appear in Maple strings and the integers in the range 1..255 via the (8-bit) ASCII character set. These procedures are similar to the homonymous operators in Pascal (and its descendents) and other languages in which characters are not an integer data type.
The Char(n) function, where n is an integer in the range 1..255, evaluates to the character (string of length one) whose ASCII code point is n. The number 0 is also accepted and, in this case, the empty string is returned.
The Ord(s) function maps characters to their ASCII code points. As a special case, Ord⁡ (in which the argument is the empty string) evaluates to 0. Given any nonempty string s, Ord⁡s is equivalent to Ord⁡s1, which evaluates to the ASCII code point of the character s1.
Note the relations Char( Ord( s ) ) = s[ 1 ], for any nonempty string s, and Ord( Char( n ) ) = n, for any integer n in the range 0..255. Thus, Char and Ord are nearly mutual inverses.
These functions are part of the StringTools package, and so they can be used in the form Char(..) only after executing the command with(StringTools). However, they can always be accessed through the long form of the command by using the form StringTools[Char](..).
All of the StringTools package commands treat strings as (null-terminated) sequences of 8-bit (ASCII) characters. Thus, there is no support for multibyte character encodings, such as unicode encodings.
with⁡StringTools:
Ord⁡
0
Ord⁡a
97
Ord⁡4
52
Ord⁡40a
map⁡Ord,Explode⁡abcdefghijklmnopqrstuvwxyz
97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122
Char⁡0
Char⁡32
Char⁡65
A
Char⁡127
Char⁡300
Error, (in StringTools:-Char) integer argument is too large
evalb⁡cat⁡op⁡map⁡Char,`$`⁡1..255=convert⁡`$`⁡1..255,bytes
true
See Also
cat
convert
map
op
seq
string
StringTools[Explode]
Download Help Document