Escape sequences and escape characters

Escape sequences and escape characters

Escape sequences and escape characters

From CodeCodex

Escape characters (also called escape sequences or escape codes) are used to signal an alternative interpretation of a series of characters. Most commonly, escape characters are used to solve the problem of using special characters inside a string declaration.

For example, if you wanted String A to have the value:

The question is, "to be or not to be"

You would need to use an escape character to keep the compiler from interpreting the " character as the end of the string:

String A = "The question is \"to be or not to be\""

Contents

[edit] Implementations

[edit] VB

Visual Basic (VB) escape characters:

For this Use this Setting x to: Printing x will yield:
" "" or Chr(34) "He said ""hi"""

"He said " & Chr(34) & "hi" & Chr(34)

He said "hi"
[enter] vbCrLf "He said " & vbCrLf & "he would" He said
he would

[edit] C / C++

C and C++ escape characters:

For this Use this Setting x to: Printing x will yield:
' \' "Don\'t do that" Don't do that
" \" "She said \"hi\"" She said "hi"
 ? \? "Who are you\?" Who are you?
\ \ "Backslash: \" Backslash: \
[newline] \n "1\n2" 1
2
[horizontal tab] \t "1\t2" 1 2
[backspace] \b "12\b3" 13
[16 bit unicode] \uxxxx "Katakana a: \u30A1" Katakana a: ァ
[32 bit unicode] \Uxxxxxxxx "Katakana a: \U000030A1" Katakana a: ァ
[numeric escape sequence.] \xnn "Printing the ESC character: \x1Bzyxwu" "Printing the ESC character: yxwu"

[edit] Delphi

Delphi escape characters:

For this Use this Setting x to: Printing x will yield:
' '' 'Don''t do that'

Remark: This is not a double quote, but two single quotes!

Don't do that
[16 or 32-bit Unicode] #d or #$x 'First Line'#13#10'Second Line' First Line
Second Line

[edit] Java

Java escape characters:

[edit] Single Characters

For this Use this Setting x to: Printing x will yield:
' \' "Don\'t do that" Don't do that
" \" "She said \"hi\"" She said "hi"
\ \ "Backslash: \" Backslash: \
[newline] \n "1\n2" 1
2
[horizontal tab] \t "1\t2" 1 2
[backspace] \b "12\b3" 13
[16 bit unicode] \uxxxx "Katakana a: \u30A1" Katakana a: ァ
[32 bit unicode] \Uxxxxxxxx "Katakana a: \u000030A1" Katakana a: ァ

[edit] Unicode

Unicode escape characters:

For this Use this Setting x to: Printing x will yield:
' \u0027 "Don\u0027t do that" Don't do that
" \u0022 "She said \u0022hi\u0022" She said "hi"
\ \u0008 "Backslash: \u0008" Backslash: \
[newline] \u000a "1\u000a2" 1
2
[horizontal tab] \u0009 "1\u00092" 1 2
[backspace] \u0008 "12\u00083" 13

[edit] PHP

PHP escape characters:

[edit] Single quoted strings

For this Use this Setting x to: Printing x will yield:
' \' 'Don\'t do that' Don't do that
\ \ 'This is a backslash: \'

Remark: Only necessary before a single quote or at the end of a string.

This is a backslash: \

[edit] Double quoted strings

For this Use this Setting x to: Printing x will yield:
" \" "She said \"hi\"" She said "hi"
\ \ "Backslash: \" Backslash: \
$ \$ "100\$" 100$
[newline, LF, 0x0A] \n "1\n2" 1
2
[carriage return, CR, 0x0D] \r "1\r2" 2
[horizontal tab] \t "1\t2" 1      2

[edit] Python

Python escape characters:

For this Use this Setting x to: Printing x will yield:
' \' "Don\'t do that" Don't do that
" \" "She said \"hi\"" She said "hi"
\ \ "Backslash: \" Backslash: \
[newline] \n "1\n2" 1
2
[carriage return] \r "1\r2" 2 overwrites the 1
[horizontal tab] \t "1\t2" 1 2
[backspace] \b "12\b3" 13
[16 bit unicode] \uxxxx "Katakana a: \u30A1" Katakana a: ァ
[32 bit unicode] \Uxxxxxxxx "Katakana a: \u000030A1" Katakana a: ァ

[edit] Seed7

Seed7 escape characters:

For this Use this Setting x to: Printing x will yield:
' \' "Don\'t do that" Don't do that
" \" "She said \"hi\"" She said "hi"
\ \ "Backslash: \" Backslash: \
[newline] \n "1\n2" 1
2
[horizontal tab] \t "1\t2" 1 2
[backspace] \b "12\b3" 13
[16 bit unicode] #xxxx\ "Katakana a: #30A1\" Katakana a: ァ
[32 bit unicode] #xxxxxxxx\ "Katakana a: #000030A1\" Katakana a: ァ
[numeric escape sequence.] \nn\ "Printing the ESC character: \zyxwu" "Printing the ESC character: yxwu"

[edit] SQL

SQL escape characters:

For this Use this Setting x to: Printing x will yield:
' \' "Don\'t do that" Don't do that
" \" "She said \"hi\"" She said "hi"
\ \ "Backslash: \" Backslash: \
[newline] \n "1\n2" 1
2

[edit] URL

URL escape characters:

For this Use this Setting x to: Printing x will yield:
Space %20 help%20me help me
% %25 100%25%20pure 100% pure
< %3C x%3Cy x<y
> %3E x%3Ey x>y
Ascii-Code %xx

[edit] XML

XML escape characters:

For this Use this Setting an element to: will yield:
' &apos; Don&apos;t do that Don't do that
" &quot; She said &quot;hi&quot; She said "hi"
& &amp; H&amp;M H&M
< &lt; a d is a &lt; a d is a <
> &gt; 5&gt;6 5>6
Unicode (hex) &#xXXX; a d is a &#x64; a d is a d
Unicode (dec) &#123; sleeps like &#90; sleeps like Z

[edit] JSON

For this Use this Setting an element to: will yield:
' \' Don\'t do that Don't do that
" \" She said \"hi\" She said "hi"
\ \ H\M H\M
[Line Break] \n Line\nbreak. Line
break

Back to posts
Comments:

Post a comment


pacman, rainbows, and roller s