
String.substring() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
814
|
ActionScript Language Reference
Example
var fullName = "Steven Sid Mumby";
middleName = fullName.substr(7, 3); // Assigns "Sid" to middleName
firstName = fullName.substr(0, 6); // Assigns "Steven" to firstName
lastName = fullName.substr(11); // Assigns "Mumby" to lastName
// Notice the negative starting indexes...
middleName = fullName.substr(-9, 3); // Assigns "Sid" to middleName
firstName = fullName.substr(-16, 6); // Assigns "Steven" to firstName
lastName = fullName.substr(-5); // Assigns "Mumby" to lastName
See Also
String.slice(), String.substring(); “Combining String Examination with Substring Extrac-
tion,” and “The substr() function,” in Chapter 4
String.substring() Method
extract a substring from a string, based on positive character positions
Flash 5
string.substring(startIndex, endIndex)
Arguments
startIndex The positive integer position of the first character to extract from string.If
negative, 0 is used.
endIndex The positive integer position of the character after the last character to extract
from
string. Defaults to string.length if omitted. If negative, 0 is used.
Returns
A substring of string, starting at startIndex and ending at endIndex – 1, where both
startIndex and endIndex are zero-relative.
Description
The substring() method is one of three methods ...