Next: search
Up: Methods
Previous: match
Contents
replace
Description
Replaces the text found by a regular expression or a string with other text.
Syntax
- StringObj.replace(rgExp, replaceText)
- "String Literal".replace(rgExp, replaceText)
- "String Literal".replace(text, replaceText[, bReplaceAll])
- StringObj.replace(text, replaceText[, bRepalceAll])
Parameters
- rgExp
- A Regular Expression object describing what to search for.
- replaceText
- A String object or literal containing the text to replace for every successful match of rgExp in stringObj.
- text
- String. Specifies the text to search for.
- bReplaceAll
- Optional. Boolean. Determines whether to replace all found patterns in the string.
Returns
The result of the replace method is a copy of stringObj after all replacements have been made.
Example
var str = "thanksHellosfsdgfsdgHello";
while (str.search("Hello") >= 0)
str = str.replace("Hello", "world");
Copyright ©2000-2010 Shanghai TopCMM Software Technologies. All Rights Reserved.