In computing, an escape sequence is a sequence of characters that has a special semantic meaning based on an established convention that specifies an escape character prefix in addition to the syntax of the rest of the text of a sequence. A convention can define any particular character code as a sequence prefix. Some conventions use a normal, printable character such as backslash (\) or ampersand (&). Others use a non-printable (a.k.a. control) character such as ASCII escape.

Escape sequences date back at least to the 1874 Baudot code. Common escape sequences include: carriage return , newline , tab . To account for the fact that using a printable character for escape causes that character to lose its normal meaning, a sequence of two backslash characters (<code>\\</code>) encodes a single backslash. An escape sequence can also specify a character by its code value. For example, the backslash can be encoded as either <code>\x5c</code> or <code>\134</code> which specify the character code value as hexadecimal and octal, respectively.

A backslash immediately followed by a newline (which is necessarily outside of a string literal) does not mark an escape sequence. The C preprocessor joins the line with the subsequent line.

Quoting escape

When an escape character is needed within a string literal, there are two common strategies:

  • Doubled delimiter For example, <code><nowiki>'He didnt do it.'</nowiki></code>) can be used to enable ANSI escape sequence support. In DOS via <code>$e</code> in the PROMPT command), and in 16-bit Windows via a command window. In Unix and Unix-like systems, the ANSI escape sequences are generally supported by the shell. The rise of GUI applications has reduced the use of escape sequences, yet the ability to provide full-screen, text-based applications is still available.

Control sequence

A control sequence is a sequence of characters that changes the state of a computer peripheral instead of conveying the normal information that the characters represent. In an ANSI escape sequence, the escape sequence prefix, called control sequence introducer, can be either ASCII ESC (decimal 27) followed by <code>[</code> or CSI (decimal 155). Notable systems that did not use an escape character for control sequences include:

  • The Hayes command set defines a modal control sequence, <code>+++</code>, which switches from command to online mode. To ensure that the sequence is interpreted as a control sequence instead of embedded in content, the sender stops communication for one second before and after sending . When the modem detects condition, it switches from normal mode (sending characters to the phone) to a command mode in which the data is interpreted a command. Sending the O command switches back to the normal mode.

</references>