String.split() - MACROMEDIA FLASH MX 2004-ACTIONSCRIPT LANGUAGE Reference

Actionscript language reference
Table of Contents

Advertisement

String.split()

Availability
Flash Player 5.
Usage
my_str.split("delimiter":String, [limit:Number]) : Number
Parameters
A string; the character or string at which
delimiter
A number; the number of items to place into the array. This parameter is optional.
limit
Returns
An array; an array containing the substrings of
Description
Method; splits a String object into substrings by breaking it wherever the specified
parameter occurs and returns the substrings in an array. If you use an empty string (
delimiter, each character in the string is placed as an element in the array.
If the
delimiter
returned array.
Example
The following example returns an array with five elements:
var my_str:String = "P,A,T,S,Y";
var my_array:Array = my_str.split(",");
for (var i = 0; i<my_array.length; i++) {
trace(my_array[i]);
}
/* output:
P
A
T
S
Y
*/
The following example returns an array with two elements,
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 (
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]);
}
804
Chapter 2:
parameter is undefined, the entire string is placed into the first element of the
splits.
my_str
.
my_str
and
"P"
"A"
) for the
""
delimiter
) as a
""
:
parameter,
delimiter

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Flash mx

Table of Contents