词条 | Escape character | |
释义 |
In computing and telecommunication, an escape character is a character which invokes an alternative interpretation on subsequent characters in a character sequence. An escape character is a particular case of metacharacters. Generally, the judgment of whether something is an escape character or not depends on context. DefinitionAn escape character may not have its own meaning, so all escape sequences are of two or more characters. Escape characters are part of the syntax for many programming languages, data formats, and communication protocols. For a given alphabet an escape character's purpose is to start character sequences (so named escape sequences), which have to be interpreted differently from the same characters occurring without the prefixed escape character. There are usually two functions of escape sequences. The first is to encode a syntactic entity, such as device commands or special data, which cannot be directly represented by the alphabet. The second use, referred to as character quoting, is to represent characters, which cannot be typed in current context, or would have an undesired interpretation. In the latter case an escape sequence is a digraph consisting of an escape character itself and a "quoted" character. Control characterGenerally, an escape character is not a particular case of (device) control characters, nor vice versa. If we define control characters as non-graphic, or as having a special meaning for an output device (e.g. printer or text terminal) then any escape character for this device is a control one. But an escape character such as the backslash ("\\"), used in programming , is graphic and hence is not a control character. Conversely most (but not all) of the ASCII "control characters" have some control function in isolation, therefore are not escape characters. In many programming languages an escape character can form an escape sequence which represents a control character. For example, {{code|\}} might represent a line break . As example you can type backslash by holding AltGr+q ExamplesJavaScriptJavaScript uses the \\ (backslash) as an escape character for:[1][2]
Note that the ASCII escape characterThe ASCII "escape" character (octal: Early reference to the term "escape character" is found in Bob Bemer's IBM technical publications, who is credited with inventing this mechanism during his work on the ASCII character set.[3] 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. 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. In user interfaces of the 1970s–1980s it was not uncommon to use this key as an escape character, but in modern desktop computers such use is dropped. Sometimes the key was identified with AltMode (for alternative mode). Even with no dedicated key, the escape character code could be generated by typing Programming and data formatsMany modern programming languages specify the doublequote character ( C, C++, Java, and Ruby all allow exactly the same two backslash escape styles. The PostScript language and Microsoft Rich Text Format also use backslash escapes. The quoted-printable encoding uses the equals sign as an escape character. URL and URI use %-escapes to quote characters with a special meaning, as for non-ASCII characters. The ampersand ( Some programming languages also provide other ways to represent special characters in literals, without requiring an escape character (see e.g. delimiter collision). Communication protocolsThe Point-to-Point Protocol uses the Bourne shellIn Bourne shell (sh), the asterisk (
Windows Command PromptThe Windows command-line interpreter uses a caret character ( For example, on the Windows Command Prompt, this will result in a syntax error. echo whereas this will output the string: {{code|lang=dos|code= echo ^ Windows PowerShellIn Windows backslash is used as path separator, therefore it generally can't be used as an escape character. PowerShell uses backtick[5] ( ` ) instead. For example, the following command: echo "`tFirst line`nNew line" Will output: New line Others
See also
Not to be confused with:
References1. ^{{cite web|url=http://mathiasbynens.be/notes/javascript-escapes |title=JavaScript character escape sequences ¡ Mathias Bynens |publisher=Mathiasbynens.be |date= |accessdate=2014-06-30}} 2. ^{{cite web|url=http://msdn.microsoft.com/en-us/library/2yfce773%28v=vs.94%29.aspx |title=Special Characters (JavaScript) |publisher=Msdn.microsoft.com |date=2014-06-20 |accessdate=2014-06-30}} 3. ^{{cite web|url=http://www.bobbemer.com/ESCAPE.HTM|title=How Bob Bemer Invented the ESCAPE Sequence and Key|first=Bob|last=Bemer|date=|website=www.bobbemer.com|accessdate=22 March 2018}} 4. ^{{cite web |url=https://technet.microsoft.com/en-us/library/cc723564.aspx |title=The Windows NT Command Shell |author=Tim Hill |year=1998 |publisher=MacMillan Technical Publishing |accessdate=2010-01-13}} 5. ^{{cite web |url=https://technet.microsoft.com/en-us/library/hh847755.aspx |title=about_Escape_Characters |publisher=Msdn.microsoft.com |date=2014-05-08 |accessdate=2016-11-24}} External links
2 : Pattern matching|Control characters |
|
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。