Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Escape sequence
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Quoting escape== ===Overview=== When an [[escape character]] is needed within the quoted/escaped string, there are two strategies used within programming and scripting languages: * doubled delimiter (e.g. <code><nowiki>'He didn''t do it.'</nowiki></code>)<ref name="IEY"/> * secondary escape sequence An example of the latter is in the use of the caret (<code>^</code>). E.g. this outputs "You can do so via Cut&Paste" in [[cmd.exe|CMD]]. (otherwise, the ampersand has a restricted use)<ref name="CMD.a"/> echo You can do so via Cut^&Paste ===In detail=== {{see|String literal#Escape sequences}} {{see also|Escape sequences in C}} A common use of escape sequences is in fact to remove control characters found in a binary data stream so that they will not cause their control function by mistake. In this case, the control character is replaced by a defined "escape character" (which need not be the US-ASCII escape character) and one or more other characters; after exiting the context where the control character would have caused an action, the sequence is recognized and replaced by the removed character.<ref name="CMD.a"/> To transmit the "escape character" itself, two copies are sent.<ref name="IEY"/> In many [[programming language]]s and command line interfaces escape sequences are used in [[character literal]]s and [[string literal]]s, to express characters which are not printable or clash with the syntax of characters or strings. For example, [[control characters]] themselves might not be allowed to be placed in the program coded by the editor program, or may have undesirable side-effects if typed into a command. The end-of-quote character is also a problem for programmers that can be solved by escaping it. In most contexts the escape character is the [[backslash]] ("'''\'''"). ===Samples=== For example, the single quotation mark character might be expressed as <code><nowiki>'\''</nowiki></code> since writing <code><nowiki>'''</nowiki></code> is not acceptable. Many modern programming languages specify the doublequote character (<code><nowiki>"</nowiki></code>) as a [[delimiter]] for a string literal. The backslash escape character typically provides ways to include doublequotes inside a string literal, such as by modifying the meaning of the doublequote character embedded in the string (<code><nowiki>\"</nowiki></code>), or by modifying the meaning of a sequence of characters including the hexadecimal value of a doublequote character (<code><nowiki>\x22</nowiki></code>). Both sequences encode a literal doublequote (<code><nowiki>"</nowiki></code>). In [[Perl]] or [[Python (programming language)|Python]] 2 <syntaxhighlight lang="perl"> print "Nancy said "Hello World!" to the crowd."; </syntaxhighlight> produces a syntax error, whereas: <syntaxhighlight lang="perl"> print "Nancy said \"Hello World!\" to the crowd."; ### example of \" </syntaxhighlight> produces the intended output. Another alternative: <syntaxhighlight lang="perl"> print "Nancy said \x22Hello World!\x22 to the crowd."; ### example of \x22 </syntaxhighlight> uses "\x" to indicate the following two characters are hexadecimal digits, "22" being the ASCII value for a doublequote in hexadecimal. [[C (programming language)|C]], [[C++]], [[Java (programming language)|Java]], and [[Ruby (programming language)|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 [[percent-encoding]] to quote characters with a special meaning, as for non-ASCII characters. Another similar (and partially overlapping) syntactic trick is [[stropping (syntax)|stropping]]. Some programming languages also provide other ways to represent special characters in literals, without requiring an escape character (see e.g. [[delimiter collision]]).
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Escape sequence
(section)
Add topic