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 |
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 |
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" |
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 |
Java 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] | \uxxxx | "Katakana a: \u30A1" | Katakana a: ァ |
[32 bit unicode] | \Uxxxxxxxx | "Katakana a: \u000030A1" | Katakana a: ァ |
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 |
PHP escape characters:
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: \ |
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 |
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: ァ |
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" |
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 |
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 |
XML escape characters:
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 |
< | < | a d is a < | a d is a < |
> | > | 5>6 | 5>6 |
Unicode (hex) | &#xXXX; | a d is a d | a d is a d |
Unicode (dec) | { | sleeps like Z | sleeps like Z |
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 |