S > String.slice |
![]() ![]() ![]() |
String.slice
Availability
Flash Player 5.
Usage
myString
.slice(
start
, [end
])
Parameters
start
A number specifying the index of the starting point for the slice. If start
is a negative number, the starting point is determined from the end of the string, where -1 is the last character.
end
A number specifying the index of the ending point for the slice. If end
is not specified, the slice includes all characters from start
to the end of the string. If end
is a negative number, the ending point is determined from the end of the string, where -1 is the last character.
Returns
Nothing.
Description
Method; extracts a slice, or substring, of the specified String object; then returns it as a new string without modifying the original String object. The returned string includes the start
character and all characters up to (but not including) the end
character.
Example
The following example sets a variable, text
, creates an instance of the String object, s
, and passes it the text
variable. The slice
method extracts a section of the string contained in the variable and the trace
action sends it to the Output window.
text = "lexington"; s = new String( text ); trace(s.slice( 1, 3 )); trace(s);
The Output window displays ex
.
The following code produces the same result, but the parameter passed to the String function is a string instead of a variable.
s = new String( "lexington" ); trace(s.slice( 1, 3 )); trace(s);
The Output window displays ex
.
![]() ![]() ![]() |