Char - Maple Help

StringTools

 Char
 map a number to the corresponding character
 Ord
 map a character to its ASCII code point

 Calling Sequence Char( n ) Ord( s )

Parameters

 n - integer in the range $0..255$ s - Maple string

Description

 • 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, $\mathrm{Ord}\left(""\right)$ (in which the argument is the empty string) evaluates to $0$. Given any nonempty string s, $\mathrm{Ord}\left(s\right)$ is equivalent to $\mathrm{Ord}\left({s}_{1}\right)$, which evaluates to the ASCII code point of the character ${s}_{1}$.
 • 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.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{Ord}\left(""\right)$
 ${0}$ (1)
 > $\mathrm{Ord}\left("a"\right)$
 ${97}$ (2)
 > $\mathrm{Ord}\left("4"\right)$
 ${52}$ (3)
 > $\mathrm{Ord}\left("40a"\right)$
 ${52}$ (4)
 > $\mathrm{map}\left(\mathrm{Ord},\mathrm{Explode}\left("abcdefghijklmnopqrstuvwxyz"\right)\right)$
 $\left[{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}\right]$ (5)
 > $\mathrm{Char}\left(0\right)$
 ${""}$ (6)
 > $\mathrm{Char}\left(32\right)$
 ${""}$ (7)
 > $\mathrm{Char}\left(65\right)$
 ${"A"}$ (8)
 > $\mathrm{Char}\left(127\right)$
 ${""}$ (9)
 > $\mathrm{Char}\left(300\right)$
 > $\mathrm{evalb}\left(\mathrm{cat}\left(\mathrm{op}\left(\mathrm{map}\left(\mathrm{Char},\left[\mathrm{}\left(1..255\right)\right]\right)\right)\right)=\mathrm{convert}\left(\left[\mathrm{}\left(1..255\right)\right],'\mathrm{bytes}'\right)\right)$
 ${\mathrm{true}}$ (10)