A string literal is a sequence of characters inside a pair of double quotes or single quotes:
var a = "foo"; var b = 'foo'; trace(a == b); // true
The only difference between the two forms is that single-quoted literals allow string interpolation.
String literals may occupy multiple lines; In which case, each line of the string will be punctuated with a '\n' newline character (See the escape sequences chart below).
var str = "Line one Line two Line three"; trace(str);
Note that indentation will also be included in the string, such as with the example below.
class X { function foo() { var str = "a b c"; } }
The str
variable will have four spaces before 'b' and 'c'.
Sequence | Meaning | Unicode codepoint (decimal) | Unicode codepoint (hexadecimal) |
---|---|---|---|
\t | horizontal tab (TAB) | 9 | 0x09 |
\n | new line (LF) | 10 | 0x0A |
\r | new line (CR) | 13 | 0x0D |
\" | double quote | 34 | 0x22 |
\' | single quote | 39 | 0x27 |
\\ | backslash | 92 | 0x5C |
\NNN | ASCII escape where NNN is 3 octal digits | 0 - 127 | 0x00 - 0x7F |
\xNN | ASCII escape where NN is a pair of hexadecimal digits | 0 - 127 | 0x00 - 0x7F |
\uNNNN | Unicode escape where NNNN is 4 hexadecimal digits | 0 - 65535 | 0x0000 - 0xFFFF |
\u{N...} | Unicode escape where N... is 1-6 hexadecimal digits | 0 - 1114111 | 0x000000 - 0x10FFFF |