REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 23-Feb-2010 Edit History |
This datatype has not yet been documented for R3.
Characters are not strings; they are the individual values from which strings are constructed. A character can be printable, unprintable, or a control symbol.
A char! value is written as a number sign (#) followed by a string enclosed in double quotes. The number sign is necessary to distinguish a character from a string:
#"R" ; the single character: R "R" ; a string with the character: R
Characters can include escape sequences that begin with a caret(^)and are followed by one or more characters of encoding. This encoding can include the characters #"^A'" to #"^Z'" for control A to control Z (upper and lower case are the same):
#"^A" #"^Z"
In addition, if parens are used within the character, they specify a special value. For example, null can be written as:
"^@" "^(null)" "^(00)"
The last line is written in hex format (base 16). Up to 4 hex digits can be provided, to cover all 16 bit Unicode characters (code-points).
Following is a table of control characters that can be used in REBOL.
Character | Definition |
---|---|
#"^(null)" or #"^@" | null (zero) |
#"^(line)", or #"^/" | new line |
#"^(tab)" or #"^-" | horizontal tab |
#"^(page)" | new page (and page eject) |
#"^(esc)" | escape |
#"^(back)" | backspace |
#"^(del)" | delete |
#"^^" | caret character |
#"^"" | quotation mark |
#"(0)" to #"(FFFF)" | hex forms of characters |
Characters can be converted to and from other datatypes with the to-char function:
probe to-char "a"
#"a"
probe to-char "z"
#"z"
Characters follow the ASCII standard and can be constructed by specifying a character's numeric equivalent:
probe to-char 65
#"A"
probe to-char 52
#"4"
probe to-char 52.3
#"4"
Another method of obtaining a character is to get the first character from a string:
probe first "ABC"
#"A"
While characters in strings are not case sensitive, comparison between individual characters is case sensitive:
probe "a" = "A"
true
probe #"a" = #"A"
false
However, when used in many types of functions, the comparison is not case sensitive unless you specify that option. Examples are:
select [#"A" 1] #"a"
1
select/case [#"A" 1] #"a"
none
find "abcde" #"B"
"bcde"
find/case "abcde" #"B"
none
switch #"A" [#"a" [print true]]
true
Use char? to determine whether a value is a char! datatype.
probe char? "a"
false
probe char? #"a"
true
Use the form function to print a character without the number sign:
probe form #"A"
"A"
Use mold on to print a character with the number sign and double quotes (and escape sequences for those characters that require it.):
probe mold #"A"
{#"A"}
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |