Escape sequences
The following escape sequences can be used inside a string and will be translated into another character. The leading "\" denotes the escape sequence and the characters after specify which character will be used.
Meaning | Character |
---|---|
backspace | \b |
tabulator character | \t |
linefeed | \n |
form feed | \f |
carriage return (enter) | \r |
backslash | \\ |
single quotation mark | \' |
double quotation mark | \" |
zero character | \0 |
ASCII character as octal number | \ + 000 (up to 3 characters) |
ASCII character as hexadecimal number | \x + hh (up to 2 characters) |
unicode character as hexadecimal number | \u + hhhh (up to 6 characters) |
In addition to the specific escape sequences, ASCII and Unicode characters can be used.
ASCII characters as octal number are written immediately after the leading backslash. Up to three characters immediately after this will be used to form the ASCII character. If less than 3 characters are used to form the ASCII character, the following text should be separated with a character outside the 0-7 range. Otherwise they will be counted as belonging to the escape sequence and influence the resulting ASCII character.
ASCII characters in hexadecimal number are written with the prefix \x. The next one or two characters are used to form the ASCII character. If only one character is used, the following text should be separated from the escape sequence with a character outside the 0-9 and A-F (or a-f) range.
Unicode characters are written as hexadecimal number with the prefix \u. After the prefix, up to six characters can be placed to form the unicode character. If less than 6 characters are used to form the unicode character, the following text should be separated from the escape sequence with a character outside the 0-9 and A-F (or a-f) range.
Example
In this example some escape sequences are written to a text-edit widget.
main()
{
string charas = "\' \74 \x7B \u300B \\ \n \t \x40 \100 \u40";
TEXT_EDIT1.text(charas);
}
Output: