Data types: char

Represents a single 16-bit UNICODE character (Supports code points from UNICODE plane 0).

Type syntax

char

Literal syntax

'single‑character'

'\special‑character'

'\x4‑hex‑digits'

Discussion

The char literal consists of a single UNICODE character enclosed between a pair of '...' (single quote) signs. Special characters including the single quote sign ' itself and characters that can't be entered directly from the keyboard are expressed by escape sequences prefixed with the \ (backslash) sign. The literal can be used within expressions wherever a char operand is expected. The type name char, in turn, is designated to be used in declarations of data members. For example:

var char currency  =  '$';
var char gammaSign = '\x0393';

The following table shows the entire set of supported escape sequences. Each sequence starts with a \ (backslash) sign. The Chora compiler will automatically replace each found escape sequence with the corresponding character code. Please note the usage of escape sequences to represent the ' (single quote) and the \ (backslash) signs:

Escape sequence

Short description

\\

Character with code 0x005C (the \ backslash sign)

\'

Character with code 0x0027 (the ' single quote sign)

\"

Character with code 0x0022 (the " double quote sign)

\x####

Character in hexadecimal notation with 4 hex digits

\n

Character with code 0x000A (corresponds to ASCII code Newline)

\a

Character with code 0x0007 (corresponds to ASCII code Alert)

\b

Character with code 0x0008 (corresponds to ASCII code Backspace)

\f

Character with code 0x000C (corresponds to ASCII code Form-feed)

\r

Character with code 0x000D (corresponds to ASCII code Carriage return)

\t

Character with code 0x0009 (corresponds to ASCII code Tabulator)

\v

Character with code 0x000B (corresponds to ASCII code vertical tab)

\0

Character with the code 0

Instant properties

The following instant properties provide a convenient interface to access and evaluate char operands:

Instant property name

Short description

lower

Represents the lower case version of a char operand.

upper

Represents the upper case version of a char operand.

Arithmetic and string concatenation operations

You can combine a char operand with other operands to expressions. The following table provides an overview of the possible operations:

Operator

Short description

+

String concatenation or char and integer addition.

-

Difference between two char codes or char and integer subtraction.

Comparison operations

You can compare two char operands in order to test whether these are equal or not. The following table provides an overview of the possible operations:

Operator

Short description

==

Equality

!=

Inequality

<

Less than

>

Greater than

<=

Less than or equal

>=

Greater than or equal

Type conversions

Chora reacts sensitive when mixing operands of different data types within an operation. To avoid compiler warnings or even errors you can convert between char and integer operands explicitly.