User Guide

214 Working with Strings
str = str + area;
// str == "Area = 28.274333882308138"
However, you can use parentheses for grouping to provide context for the + operator, as the
following example shows:
trace("Total: $" + 4.55 + 1.45);
//"Total: $4.551.45"
trace("Total: $" + (4.55 + 1.45));
//"Total: $6"
Finding substrings and patterns in strings
Substrings are sequential characters within a string. For example, the string "abc" has the
following substrings:
"", "a", "ab", "abc", "b", "bc", "c". You can use ActionScript
methods to locate substrings of a string.
Patterns are defined in ActionScript by strings or by regular expressions. For example, the
following regular expression defines a specific pattern—the letters A, B, and C followed by a
digit character (the forward slashes are regular expression delimiters):
/ABC\d/
ActionScript includes methods for finding patterns in strings and for replacing found matches
with replacement substrings. These methods are described in the following sections.
Regular expressions can define intricate patterns. For more information, see Chapter 10,
“Using Regular Expressions,” on page 285.
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