Escape sequences |
Top Previous Next |
Glossary > Escape sequences
The backslash character (\) is used to introduce an escape sequence, which allows the visual representation of certain nongraphic characters. For example, the constant \n is used to the single newline character. A backslash is used with octal or hexadecimal numbers to represent the ASCII symbol or control code corresponding to that value; for example, '\03' for Ctrl-C or '\x3F' for the question mark. You can use any string of up to three octal or any number of hexadecimal numbers in an escape sequence, provided that the value is within legal range for data type char (0 to 0xff). (For the definition of regular expression only too hexadecimal numbers are taken.) Larger numbers generate the compiler error "value is too large". For example, the octal number \777 is larger than the maximum value allowed (\377) and will generate an error. The first nonoctal or nonhexadecimal character encountered in an octal or hexadecimal escape sequence marks the end of the sequence.
Take this example.
out << "\x0072.1A Simple Operating System";
This is intended to be interpreted as \x007 and "2.1A Simple Operating System". However, C++Builder compiles it as the hexadecimal number \x0072 and the literal string ".1A Simple Operating System". To avoid such problems, rewrite your code like this:
out << "\x007" "2.1A Simple Operating System";
Ambiguities might also arise if an octal escape sequence is followed by a nonoctal digit. For example, because 8 and 9 are not legal octal digits, the constant \258 would be interpreted as a two-character constant made up of the characters \25 and 8.
All escape sequences which can be used both in literal tokens and in regular expressions are summarized in the following table. There are even further escape sequences for regular expressions.
Note: You must use \\ to represent an ASCII backslash, as used in operating system paths.
|
This page belongs to the TextTransformer Documentation |
Home Content German |