
String.substr() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
813
On frame 1 of our movie, we load the names.txt file into our movie:
this.loadVariables("names.txt");
After ensuring that names.txt has fully loaded (see loadVariables()), we split the loaded
owners variable into an array:
splitString = String.fromCharCode(9); // Assign the Tab character to splitString
ownersArray = owners.split(splitString);
trace(ownersArray[1]); // Displays: "doug"
Note that in Flash 5 split() can take a long time to execute with large bodies of text; it is
considerably faster in Flash 6. If performance is a problem, break your data into manage-
able portions or consider using XML instead. See the XML class.
Bugs
In Flash 5, using the empty string as a delimiter adds all of string to the first element of the
array being generated. According to ECMA-262, an empty string delimiter should cause
string to be broken at each character. Similarly, multicharacter delimiters are not recog-
nized by Flash 5 and cause all of
string to be assigned to the first element of the returned
array. These bugs are fixed in Flash Player 6.
See Also
Array.join(); “The split() function,” in Chapter 4
String.substr() Method
extract a substring from a string, based on a starting position and length
Flash 5
string.substr(startIndex, length