
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
94
|
Chapter 4: Primitive Datatypes
Notice how the logical OR operator (||) lets us check two conditions at once. We’ll
study OR in Chapter 5.
You may encounter the deprecated
gt, ge, lt, and le operators, used for string com-
parison in Flash 4, when examining legacy code. The
>, >=, <, and <= operators
should be used in Flash 5 and later.
Using Built-in String Functions
With the exception of the concat() function, every tool we’ve used with strings so far
has been an operator. Now we’ll see how to use built-in functions and properties to
perform more advanced string manipulation.
To execute a built-in function on a string, we must perform a function call, which
takes the form:
string.functionName(arguments)
For example, here we execute the charAt() function on myString:
myString.charAt(2)
Many string functions return a new string derived from the original string. We assign
these return values to variables or object properties for future use, such as:
thirdCharacter = myString.charAt(2);
Character Indexing
Many of the string functions make use of a character’s index—its numeric position
relative to the string’s first character, starting at 0, not 1. The first character is num-
bered 0, the second is numbered 1, the third is numbered 2, and so on. For example,
in the string “red”, the r is at ...