
String.toLowerCase() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
815
Example R-4 is a reusable function to search for and replace all occurrences of a substring
within a string.
See Also
String.slice(), String.substr(); “Combining String Examination with Substring Extraction,”
and “The substr() function,” in Chapter 4
String.toLowerCase() Method
generate a lowercase version of a string
Flash 5
string.toLowerCase()
Returns
The lowercase equivalent of string as a new string. Characters without a lowercase equiva-
lent are left unchanged.
Description
The toLowerCase() method creates a new, lowercase version of string; it can be used for
formatting or for facilitating case-insensitive character comparisons.
Usage
Note that toLowerCase() does not modify string; it returns a completely new string.
Example
// Set msg to "this sentence has mixed caps!"
msg = "ThiS SenTencE Has MixED CaPs!".toLowerCase();
Example R-4. A search-and-replace function
function replace (origStr, searchStr, replaceStr) {
var tempStr = "";
var startIndex = 0;
if (searchStr = = "") {
return origStr;
}
if (origStr.indexOf(searchStr) != -1) {
while ((searchIndex = origStr.indexOf(searchStr, startIndex)) != -1) {
tempStr += origStr.substring(startIndex, searchIndex);
tempStr += replaceStr;
startIndex = searchIndex + searchStr.length; ...