Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Working with Text and Strings > About strings and the String class > About the String class | |||
A string is also a class and data type in the core ActionScript language. The String data type represents a sequence of 16-bit characters that might include letters, numbers, and punctuation marks. Strings are stored as Unicode characters, using the UTF-16 format. An operation on a String value returns a new instance of the string. The default value for a variable declared with the String data type is null.
For more information on strings, data, and values, see Data and Data Types.
The String class contains methods that let you work with text strings. Strings are important in working with many objects, and the methods described in this chapter are useful in working with strings used in many objects, such as TextField, XML, ContextMenu, and FileReference instances.
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.
For a sample source file, strings.fla, that shows you how to build a simple word processor that compares and retrieves string and substring selections, see the Flash Sample page at www.adobe.com/go/learn_fl_samples. Download and decompress the Samples zip file and navigate to the ActionScript2.0/Strings folder to access the sample.
|
|
|
|