Escape character

From Wikipedia, the free encyclopedia

Jump to: navigation, search

In computing and telecommunication, an escape character is a single character designated to invoke an alternative interpretation on immediately subsequent characters in a character sequence. The term escape sequence refers to the escape character and the character or characters whose meaning is modified.

Contents

[edit] Examples

[edit] Programming languages

Many modern programming languages specify the doublequote character (") as a delimiter for a string literal. The backslash \ escape character provides two ways to include doublequotes inside a string literal, either by modifying the meaning of the doublequote character embedded in the string (\" becomes "), or by modifying the meaning of the three characters that are the hexadecimal value of a doublequote character (\x22 becomes ").

In Perl:

print "Nancy said "Hello World!" to the crowd.";

produces a syntax error, whereas:

print "Nancy said \"Hello World!\" to the crowd.";  ### example of \"

produces the intended output. Another alternative:

print "Nancy said \x22Hello World!\x22 to them.";  ### example of \x22

uses numeric escape-sequence of hexadecimal "x22" for a quotemark.

C (programming language), C++, and Java (programming language) all allow exactly the same two backslash escape styles, while quoted-printable uses a slightly different numeric escape sequence.

Some programming languages also provide other ways to prevent this type of error, without requiring an escape character (see e.g. delimiter collision).

[edit] In the Bourne shell

In sh, the * character is a wildcard character expanded via globbing. Without a preceding escape character, it will expand to the names of all files in the working directory that don't start with a period if and only if there are such files, otherwise * remains unexpanded. So to refer to a file literally called "*", the shell must be told not to interpret it in this way, by preceding it with a backslash ("\"). This modifies the interpretation of the asterisk ("*"). Compare:

 
rm *    # delete all files in the current directory
 
rm \*   # delete the file named *

[edit] Categories

  • In alphabet coding schemes, a specially designated character, the occurrence of which in the data signifies that one or more of the characters to follow are from a different character code, i.e., have meanings other than normal.
  • In a text-control sequence of characters, a control character that indicates the beginning of the sequence and the end of any preceding text. This is for instance used to control text terminals and printers (see escape sequence).
  • In the ASCII character code, the character ESC with decimal code 27 and hexadecimal code 1B.

Early reference to this term is found in Bob Bemer's IBM technical publications.

The Escape key is usually found on standard PC keyboards. However it is commonly absent from keyboards for PDAs and other devices not designed primarily for ASCII communications, and not generally used as part of the common user interface for applications on the Windows operating system. The DEC VT220 series was one of the few popular keyboards that did not have a dedicated Esc key, instead using one of the keys above the main keypad.

[edit] See also

[edit] External links

PD-icon.svg This article incorporates public domain material from the General Services Administration document "Federal Standard 1037C".