Taken from AS3 Manual:
Finding a substring by character position
The substr() and substring() methods are similar. Both return
a substring of a string.
Both take two parameters. In both methods, the first
parameter is the position of the starting
character in the given string. However, in the substr()
method, the second parameter is the
length of the substring to return, and in the substring()
method, the second parameter is
the position of the character at the end of the substring
(which is not included in the returned
string). This example shows the difference between these two
methods:
var str:String = "Hello from Paris, Texas!!!";
trace(str.substr(11,15)); // Paris, Texas!!!
trace(str.substring(11,15)); // output: Pari
Finding substrings and patterns in strings 215
The slice() method functions similarly to the substring()
method. When given two nonnegative
integers as parameters, it works exactly the same. However,
the slice() method can
take negative integers as parameters, in which case the
character position is taken from the end
of the string, as shown in the following example:
var str:String = "Hello from Paris, Texas!!!";
trace(str.slice(11,15)); // Pari
trace(str.slice(-3,-1)); // !!
trace(str.slice(-3,26)); // !!!
trace(str.slice(-3,str.length)); // !!!
trace(str.slice(-8,-3)); // Texas
You can combine non-negative and negative integers as the
parameters of the slice()
method.
Finding the character position of a matching
substring
You can use the indexOf() and lastIndexOf() methods to locate
matching substrings
within a string, as the following example shows:
var str:String = "The moon, the stars, the sea, the land";
trace(str.indexOf("the")); // 10
Notice that the indexOf() method is case-sensitive.
You can specify a second parameter to indicate the index
position in the string from which to
start the search, as follows:
var str:String = "The moon, the stars, the sea, the land"
trace(str.indexOf("the", 11)); // 21
The lastIndexOf() method finds the last occurrence of a
substring in the string:
var str:String = "The moon, the stars, the sea, the land"
trace(str.lastIndexOf("the")); // 30
If you include a second parameter with the lastIndexOf()
method, the search is conducted
from that index position in the string working backward (from
right to left):
var str:String = "The moon, the stars, the sea, the land"
trace(str.lastIndexOf("the", 29)); // 21