Module Tablecloth.Char Source Functions for working with single characters.
Functions for working with single characters.
Character literals are enclosed in 'a' pair of single quotes.
let digit = '7'The functions in this module work on ASCII characters (range 0-255) only, not Unicode .
Since character 128 through 255 have varying values depending on what standard you are using (ISO 8859-1 or Windows 1252), you are advised to stick to the 0-127 range.
CreateYou can also create a Char using single quotes:
let char = 'c'Source val from_code : int -> char option Convert an ASCII code point to a character.
The full range of extended ASCII is from 0 to 255. For numbers outside that range, you get None.
Examples
Char.from_code 65 = Some 'A'Char.from_code 66 = Some 'B'Char.from_code 3000 = NoneChar.from_code (-1) = NoneSource val from_string : string -> char option Converts a string to character.
Returns None when the string isn't of length one.
Examples
Char.from_string "A" = Some 'A'Char.from_string " " = Some ' 'Char.from_string "" = NoneChar.from_string "abc" = NoneChar.from_string " a" = NoneSource val is_lowercase : char -> boolDetect lower case ASCII characters.
Examples
Char.is_lowercase 'a' = trueChar.is_lowercase 'b' = trueChar.is_lowercase 'z' = trueChar.is_lowercase '0' = falseChar.is_lowercase 'A' = falseChar.is_lowercase '-' = falseSource val is_uppercase : char -> boolDetect upper case ASCII characters.
Examples
Char.is_uppercase 'A' = trueChar.is_uppercase 'B' = trueChar.is_uppercase 'Z' = trueChar.is_uppercase 'h' = falseChar.is_uppercase '0' = falseChar.is_uppercase '-' = falseSource val is_letter : char -> boolDetect upper and lower case ASCII alphabetic characters.
Examples
Char.is_letter 'a' = trueChar.is_letter 'b' = trueChar.is_letter 'E' = trueChar.is_letter 'Y' = trueChar.is_letter '0' = falseChar.is_letter '-' = falseSource val is_digit : char -> boolDetect when a character is a number.
Examples
Char.is_digit '0' = trueChar.is_digit '1' = trueChar.is_digit '9' = trueChar.is_digit 'a' = falseChar.is_digit 'b' = falseSource val is_alphanumeric : char -> boolDetect upper case, lower case and digit ASCII characters.
Examples
Char.is_alphanumeric 'a' = trueChar.is_alphanumeric 'b' = trueChar.is_alphanumeric 'E' = trueChar.is_alphanumeric 'Y' = trueChar.is_alphanumeric '0' = trueChar.is_alphanumeric '7' = trueChar.is_alphanumeric '-' = falseSource val is_printable : char -> boolDetect if a character is a printable character
A Printable character has a Char.to_code in the range 32 to 127, inclusive (' ' to '~').
Examples
Char.is_printable 'G' = trueChar.is_printable '%' = trueChar.is_printable ' ' = trueChar.is_printable '\t' = falseChar.is_printable '\007' = falseSource val is_whitespace : char -> boolDetect one of the following characters:
'\t' (tab)'\n' (newline)'\011' (vertical tab)'\012' (form feed)'\r' (carriage return)' ' (space)Examples
Char.is_whitespace '\t' = trueChar.is_whitespace ' ' = trueChar.is_whitespace '?' = falseChar.is_whitespace 'G' = falseSource val to_lowercase : char -> charConverts an ASCII character to lower case, preserving non alphabetic ASCII characters.
Examples
Char.to_lowercase 'A' = 'a'Char.to_lowercase 'B' = 'b'Char.to_lowercase '7' = '7'Source val to_uppercase : char -> charConvert an ASCII character to upper case, preserving non alphabetic ASCII characters.
Examples
Char.to_uppercase 'a' = 'A'Char.to_uppercase 'b' = 'B'Char.to_uppercase '7' = '7'Source val to_code : char -> intConvert char to the corresponding ASCII code point .
Examples
Char.to_code 'A' = 65Char.to_code 'B' = 66Source val to_string : char -> stringConvert a character into a string.
Examples
Char.to_string 'A' = "A"Char.to_string '{' = "{"Char.to_string '7' = "7"Source val to_digit : char -> int option Converts a digit character to its corresponding Int .
Returns None when the character isn't a digit.
Examples
Char.to_digit "7" = Some 7Char.to_digit "0" = Some 0Char.to_digit "A" = NoneChar.to_digit "" = NoneTest two Char s for equality