Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > String > substring (String.substring method) | |||
Returns a string comprising the characters between the points specified by the start and end parameters. If the end parameter is not specified, the end of the substring is the end of the string. If the value of start equals the value of end, the method returns an empty string. If the value of start is greater than the value of end, the parameters are automatically swapped before the function executes and the original value is unchanged.
Availability: ActionScript 1.0; Flash Player 5
start:Number - An integer that indicates the position of the first character of my_str used to create the substring. Valid values for start are 0 through String.length - 1. If start is a negative value, 0 is used.
end:Number - An integer that is 1+ the index of the last character in my_str to be extracted. Valid values for end are 1 through String.length. The character indexed by the end parameter is not included in the extracted string. If this parameter is omitted, String.length is used. If this parameter is a negative value, 0 is used.
String - A substring of the specified string.
The following example shows how to use substring():
var my_str:String = "Hello world"; var mySubstring:String = my_str.substring(6,11); trace(mySubstring); // output: world
The following example shows what happens if a negative start parameter is used:
var my_str:String = "Hello world"; var mySubstring:String = my_str.substring(-5,5); trace(mySubstring); // output: Hello
For another example, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download and decompress the Samples zip file and go to the ActionScript2.0\Strings folder to access the Strings.fla file.
Flash CS3