Split (String. split method)
Public split (delimiter: String, [limit: Number]): Array
Disconnects the String object from all locations where the specified delimiter parameter appears, splits it into substrings, and returns the substrings in array form. If an empty string ("") is used as the separator, each character in the string is placed as an element in the array.
If the delimiter parameter is not defined, the entire string is placed in the first element of the returned array.
Availability: ActionScript 1.0; Flash Player 5
Parameters
Delimiter: String-a String; a character or String at which my_str is split.
Limit: Number [optional]-Number of projects to be placed in the array.
Return
Array-an Array containing the child string of my_str.
Example
The following example returns an array containing five elements:
The code is as follows: |
Copy code |
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 containing two elements ("P" and ":
The code is as follows: |
Copy code |
Var my_str: String = "P, A, T, S, Y "; Var my_array: Array = my_str.split (",", 2 ); Trace (my_array); // output: P,
|
The following example shows that if you use a null string ("") for the delimiter parameter, each character in the string is placed as an element in an array:
The code is as follows: |
Copy code |
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 |
There is also an example in the Strings. fla file in the sample folder of the ActionScript file. The following list specifies the typical path to this folder:
Windows: boot drive Program filesm1_mediaflash 8 Samples and TutorialsSamplesActionScript
Macintosh: Macintosh HD/Applications/Macromedia Flash 8/Samples and Tutorials/Samples/ActionScript