Flash CS3 Documentation |
|||
| Learning ActionScript 2.0 in Adobe Flash > Data and Data Types > About data types > About primitive and complex data types > String data type | |||
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.
A common way that you use the string type is to assign a string to a variable. For example, in the following statement, "L7" is a string assigned to the variable favoriteBand_str:
var favoriteBand_str:String = "L7";
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:
var greeting_str:String = "Welcome, " + 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 lists 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 |
\000 - \377
|
A byte specified in octal |
\x00 - \xFF
|
A byte specified in hexadecimal |
\u0000 - \uFFFF
|
A 16-bit Unicode character specified in hexadecimal |
Strings in ActionScript are immutable, just as they are in Java. Any operation that modifies a string returns a new string.
The String class is a built-in ActionScript class. For information on the methods and properties of the String class, see the String entry in the ActionScript 2.0 Language Reference.
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000647.html