1136
ActionScript classes
trace(my_array[i]);
}
// output:
P
A
T
S
Y
The following example returns an array with two elements,
"P"
and
"A"
:
var my_str:String = "P,A,T,S,Y";
var my_array:Array = my_str.split(",", 2);
trace(my_array); // output: P,A
The following example shows that if you use an empty string ("") for the
delimiter
parameter, each character in the string is placed as an element in the array:
var my_str:String = new String("Joe");
var my_array:Array = my_str.split("");
for (var i = 0; i<my_array.length; i++) {
trace(my_array[i]);
}
// output:
J
o
e
An example is also in the Strings.fla file in the ActionScript samples folder. The following list
gives typical paths to this folder:
■
Windows:
boot drive
\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript
■
Macintosh:
Macintosh HD
/Applications/Macromedia Flash 8/Samples and Tutorials/
Samples/ActionScript
See also
join (Array.join method)
String constructor
public String(value:String)
Creates a new String object.
NO
TE
Because string literals use less overhead than String objects and are generally easier to
use, you should use string literals instead of the constructor for the String class unless
you have a good reason to use a String object rather than a string literal.
Summary of Contents for FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
Page 1: ...ActionScript 2 0 Language Reference ...
Page 1352: ...1352 ActionScript classes ...