REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 23-Feb-2010 Edit History  

REBOL 3 Datatypes: Char!

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:


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"
probe to-char "z"

Characters follow the ASCII standard and can be constructed by specifying a character's numeric equivalent:

probe to-char 65
probe to-char 52
probe to-char 52.3

Another method of obtaining a character is to get the first character from a string:

probe first "ABC"

While characters in strings are not case sensitive, comparison between individual characters is case sensitive:

probe "a" = "A"
probe #"a" = #"A"

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"
select/case [#"A" 1] #"a"
find "abcde" #"B"
find/case "abcde" #"B"
switch #"A" [#"a" [print true]]


Use char? to determine whether a value is a char! datatype.

probe char? "a"
probe char? #"a"

Use the form function to print a character without the number sign:

probe form #"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"

  TOC < Back Next > - WIP Wiki Feedback Admin