![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
Flash Player 5.
my_str
.slice(
start
, [end
])
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
An integer that is 1+ the index of the ending point for the slice. The character indexed by the end
parameter is not included in the extracted string. If this parameter is omitted, String.length
is used. If end
is a negative number, the ending point is determined by counting back from the end of the string, where -1 is the last character.
A substring of the specified string.
Method; returns a string that includes the start
character and all characters up to (but not including) the end
character. The original String object is not modified. If the end
parameter is not specified, the end of the substring is the end of the string. If the value of start
is greater than or equal to the value of end
, the method returns an empty string.
The following example sets a variable, text
, creates a String object, my_str
, and passes it the text
variable. The slice()
method extracts a section of the string contained in the variable, and trace()
sends it to the Output panel. The example shows using both a positive and negative value for the end
parameter.
text = "Lexington";
my_str = new String( text );
trace(my_str.slice( 1, 3 )); // "ex
"
trace(my_str.slice( 1, -6 )); // "ex"
String.substr()
, String.substring()
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |