String
1135
trace("slice(1,1): "+my_str.slice(1, 1)); // slice(1,1):
trace("slice(3,2): "+my_str.slice(3, 2)); // slice(3,2):
trace("slice(-2,2): "+my_str.slice(-2, 2)); // slice(-2,2):
// slices that omit the end parameter use String.length, which equals 5
trace("slice(0): "+my_str.slice(0)); // slice(0): Lorem
trace("slice(3): "+my_str.slice(3)); // slice(3): em
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
substr (String.substr method)
,
substring (String.substring method)
split (String.split method)
public split(delimiter:String, [limit:Number]) : Array
Splits a String object into substrings by breaking it wherever the specified
delimiter
parameter occurs and returns the substrings in an array. If you use an empty string ("") as a
delimiter, each character in the string is placed as an element in the array.
If the
delimiter
parameter is undefined, the entire string is placed into the first element of
the returned array.
Availability:
ActionScript 1.0; Flash Player 5
Parameters
delimiter
:String
- A string; the character or string at which
my_str
splits.
limit
:Number
[optional] - The number of items to place into the array.
Returns
Array
- An array containing the substrings of
my_str
.
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++) {
Summary of Contents for FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
Page 1: ...ActionScript 2 0 Language Reference ...
Page 1352: ...1352 ActionScript classes ...