MACROMEDIA FLEX-FLEX ACTIONSCRIPT LANGUAGE Reference page 415

Actionscript language reference
Table of Contents

Advertisement

String.slice()
Availability
Flash Player 5.
Usage
my_str.slice(start:Number, [end:Number]) : String
Parameters
A number; the zero-based index of the starting point for the slice. If
start
number, the starting point is determined from the end of the string, where -1 is the last character.
A number; an integer that is 1+ the index of the ending point for the slice. The character
end
indexed by the
end
String.length
back from the end of the string, where -1 is the last character.
Returns
A string; a substring of the specified string.
Description
Method; returns a string that includes the
including, the
end
not specified, the end of the substring is the end of the string. If the character indexed by
the same as or to the right of the character indexed by
Example
The following example creates a variable,
method using a variety of values for both the
slice()
method is wrapped in a
the slice()
// Index values for the string literal
// positive index:
// string:
// negative index: -5-4-3-2-1
var my_str:String = "Lorem";
// slice the first character
trace("slice(0,1): "+my_str.slice(0, 1)); // output: slice(0,1): L
trace("slice(-5,1): "+my_str.slice(-5, 1)); // output: slice(-5,1): L
// slice the middle three characters
trace("slice(1,4): "+my_str.slice(1, 4)); // slice(1,4): ore
trace("slice(1,-1): "+my_str.slice(1, -1)); // slice(1,-1): ore
// slices that return empty strings because start is not to the left of end
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):
parameter is not included in the extracted string. If this parameter is omitted,
is used. If
is a negative number, the ending point is determined by counting
end
character. The original String object is not modified. If the
0 1 2 3 4
L o r e m
character and all characters up to, but not
start
, the method returns an empty string.
end
assigns it a String value, and then calls the
my_str,
start
statement that sends the output to the log file.
trace()
start
end
and
parameters.
end
Each call to
String.slice()
is a negative
parameter is
is
start
415

Advertisement

Table of Contents
loading
Need help?

Need help?

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

This manual is also suitable for:

Flex

Table of Contents