Module Tablecloth.Char 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'val fromCode : int -> char option Convert an ASCII code point to a character.
Returns None if the codepoint is outside the range of 0 to 255 inclusive.
Examples
Char.fromCode 65 = Some 'A'Char.fromCode 66 = Some 'B'Char.fromCode 3000 = NoneChar.fromCode (-1) = NoneThe full range of extended ASCII is from 0 to 255. For numbers outside that range, you get None.
val from_code : int -> char option val fromString : string -> char option Converts a string to character. Returns None when the string isn't of length one.
Examples
Char.fromString "A" = Some 'A'Char.fromString " " = Some ' 'Char.fromString "" = NoneChar.fromString "abc" = NoneChar.fromString " a" = Noneval from_string : string -> char option Queryval isLowercase : char -> boolDetect lower case ASCII characters.
Examples
Char.isLowercase 'a' = trueChar.isLowercase 'b' = trueChar.isLowercase 'z' = trueChar.isLowercase '0' = falseChar.isLowercase 'A' = falseChar.isLowercase '-' = falseval is_lowercase : char -> boolval isUppercase : char -> boolDetect upper case ASCII characters.
Examples
Char.isUppercase 'A' = trueChar.isUppercase 'B' = trueChar.isUppercase 'Z' = trueChar.isUppercase 'h' = falseChar.isUppercase '0' = falseChar.isUppercase '-' = falseval is_uppercase : char -> boolval isLetter : char -> boolDetect upper and lower case ASCII alphabetic characters.
Examples
Char.isLetter 'a' = trueChar.isLetter 'b' = trueChar.isLetter 'E' = trueChar.isLetter 'Y' = trueChar.isLetter '0' = falseChar.isLetter '-' = falseval is_letter : char -> boolval isDigit : char -> boolDetect when a character is a number
Examples
Char.isDigit '0' = trueChar.isDigit '1' = trueChar.isDigit '9' = trueChar.isDigit 'a' = falseChar.isDigit 'b' = falseval is_digit : char -> boolval isAlphanumeric : char -> boolDetect upper case, lower case and digit ASCII characters.
Examples
Char.isAlphanumeric 'a' = trueChar.isAlphanumeric 'b' = trueChar.isAlphanumeric 'E' = trueChar.isAlphanumeric 'Y' = trueChar.isAlphanumeric '0' = trueChar.isAlphanumeric '7' = trueChar.isAlphanumeric '-' = falseval is_alphanumeric : char -> boolval isPrintable : char -> boolDetect if a character is a printable character
A Printable character has a Char.toCode in the range 32 to 127, inclusive (' ' to '~').
Examples
Char.isPrintable 'G' = trueChar.isPrintable '%' = trueChar.isPrintable ' ' = trueChar.isPrintable '\t' = falseChar.isPrintable '\007' = falseval is_printable : char -> boolval isWhitespace : char -> boolDetect one of the following characters:
'\t' (tab)'\n' (newline)'\011' (vertical tab)'\012' (form feed)'\r' (carriage return)' ' (space)Examples
Char.isWhitespace '\t' = trueChar.isWhitespace ' ' = trueChar.isWhitespace '?' = falseChar.isWhitespace 'G' = falseval is_whitespace : char -> bool Modifyval toLowercase : char -> charConverts an ASCII character to lower case, preserving non alphabetic ASCII characters.
Examples
Char.toLowercase 'A' = 'a'Char.toLowercase 'B' = 'b'Char.toLowercase '7' = '7'val to_lowercase : char -> charval toUppercase : char -> charConvert an ASCII character to upper case, preserving non alphabetic ASCII characters.
Examples
toUppercase 'a' = 'A'toUppercase 'b' = 'B'toUppercase '7' = '7'val to_uppercase : char -> char ConvertConvert to the corresponding ASCII code pointcp.
cp: https://en.wikipedia.org/wiki/Code_point
Examples
Char.toCode 'A' = 65Char.toCode 'B' = 66val to_code : char -> intval toString : char -> stringConvert a character into a string.
Examples
Char.toString 'A' = "A"Char.toString '{' = "{"Char.toString '7' = "7"val to_string : char -> stringval toDigit : char -> int option Converts a digit character to its corresponding Int .
Returns None when the character isn't a digit.
Examples
Char.toDigit "7" = Some 7Char.toDigit "0" = Some 0Char.toDigit "A" = NoneChar.toDigit "" = Noneval to_digit : char -> int option Compareval equal : t -> t -> boolTest two Char s for equality
val compare : t -> t -> intval comparator : (t , identity ) Tablecloth__.TableclothComparator.t