Data types: string
Represents a 16-bit UNICODE character string. (Supports code points from UNICODE plane 0).
Type syntax
string
Literal syntax
"one‑or‑more‑characters"
" ... \special‑character ... "
" ... \x4‑hex‑digits ... "
""
Discussion
The string literal consists of a sequence of UNICODE characters enclosed between a pair of "..." (double quote) signs. Special characters including the double quote sign " itself and other characters that can't be entered directly from the keyboard are expressed by escape sequences prefixed with the \ (backslash) sign. Strings with no content (no characters between the " (double quote) signs) are considered as empty strings. The literal can be used within expressions wherever a string operand is expected. The type name string, in turn, is designated to be used in declarations of data members. For example:
var string label = "Retry"; var string message = "You really want to delete the file?"; var string text = "Alpha-Delta-Lambda: \x0391\x0394\x039B";
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 " (double quote) and the \ (backslash) signs as well as the new-line code \n necessary if you want to manually break text in several rows:
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 constructors
With the instant constructor string() you can flexibly create and format string operands dynamically at the runtime.
Instant properties
The following instant properties provide a convenient interface to access and evaluate string operands:
Instant property name |
Short description |
---|---|
Represents the number of characters within a string operand. |
|
Represents the lower case version of a string operand. |
|
Represents the upper case version of a string operand. |
Instant methods
The following instant methods provide a convenient interface to access and operate on a string operand:
Instant method name |
Short description |
---|---|
Searches in the string for a character or a substring. |
|
Inserts a substring within the string operand. |
|
Returns a leftmost part from the string operand. |
|
Returns a part from the string operand. |
|
Removes a part from the string operand. |
|
Returns a rightmost part from the string operand. |
|
Formats a string by replacing placeholders with string operands. |
|
Converts an integral number stored in the string into an int32 value. |
|
Converts an integral number stored in the string into a uint32 value. |
|
Converts an integral number stored in the string into an int64 value. |
|
Converts an integral number stored in the string into a uint64 value. |
|
Converts a number stored in the string into a float value. |
String concatenation operations
You can concatenate two string operands or a string and a character together by using the + operator.
Accessing string characters
You can select and access each character in the string operand individually by using the index [] operator.
Comparison operations
You can compare two string 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 any numbers to string operands explicitly. Similarly strings containing numbers as text can be evaluated and converted in the corresponding integer or floating point values.
Maximum string length
Constant strings (literals and constants containing strings) are limited to the maximum length of 32767 characters per string. In turn, strings created dynamically at the runtime of the application (e.g. resulting from the concatenation of two other strings) are limited only by the available RAM.