String

A string is a sequence of characters such as letters, numbers, and punctuation marks. You enter strings in an ActionScript statement by enclosing them in single or double quotation marks. Strings are treated as characters instead of as variables. For example, in the following statement, “S6″ is a string:

favoriteBand = “S6″;

You can use the addition (+) operator to concatenate, or join, two strings. ActionScript treats spaces at the beginning or end of a string as a literal part of the string. The following expression includes a space after the comma:

greeting = “Hello,” + firstName;

To include a quotation mark in a string, precede it with a backslash character (\). This is called escaping a character. There are other characters that cannot be represented in ActionScript except by special escape sequences. The following table provides all the ActionScript escape characters:

Escape Sequence Character
\b Backspace character (ASCII 8)
\f Form-feed character (ASCII 12)
\n Line-feed character (ASCII 10)
\r Carriage return character (ASCII 13)
\t Tab character (ASCII 9)
\” Double quotation mark
\’ Single quotation mark
\\ Backslash
00 – \377 A byte specified in octal
\x00 – \xFF A byte specified in hexadecimal
\u0000 – \uFFFF A 16-bit Unicode character specified in hexadecimal

String