458 Working with Text and Strings
The String class is a wrapper for the String primitive data type, and provides methods and
properties that let you manipulate primitive string values. You can convert the value of any
object into a string by using the
String() function. All the methods of the String class,
except for
concat(), fromCharCode(), slice(), and substr(), are generic, which means
the methods call the
toString() function before they perform their operations, and you can
use these methods with other non-String objects.
Because all string indexes are zero-based, the index of the last character for any
myStr string is
myStr.length - 1.
You can find a sample source file, strings.fla, in the Samples folder on your hard disk. This file
shows you how to build a simple word processor that compares and retrieves string and
substring selections.
■ In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Strings.
■ On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Strings.
Creating strings
You can call any of the methods of the String class by using the new String() constructor
method or by using a string literal value. If you specify a string literal, the ActionScript
interpreter automatically converts it to a temporary String object, calls the method, and
discards the temporary String object. You can also use the
String.length property with a
string literal.
Do not confuse a string literal with a String object. For more information on string literals and
the String object, see Chapter 5, “About literals,” on page 130.
In the following example, the line of code creates the
firstStr string literal. To declare a
string literal, use single straight quotation mark (
') or double straight quotation mark (")
delimiters.