Class: String
Description
This method replaces one or more occurrences of one string with another string.
Syntax
StringObject.replace(String lookFor,String replaceBy,
Number count,Boolean ignoreCase,String quoteChar)
Parameters
lookFor |
The string to replace with replaceBy. If not specified, the String object's value is returned unchanged. |
replaceBy |
The string that replaces lookFor. If not specified, the occurrences of lookFor are removed. |
count |
The number of occurrences to replace. A null or zero value will replace all occurrences. |
ignoreCase |
An option that indicates whether to ignore case. Valid values are 1 (ignore case) and 0 (do not ignore case). This option applies only to the source value and lookFor. The replacement string is always inserted as specified (case-sensitive). |
quoteChar |
The quote character. Substrings enclosed by the quote character are ignored. If this parameter is not supplied, or if the empty string is supplied, no special treatment of quoted substring occurs. |
Returns
A String.
When Became Available
v7.0
Example
type String STR = "Feel free, 'fly' far away!")
// "Feel free, 'fly' far away!"
type String REP1 = STR.replace("far","far ")
// First 2 occ. only: "Feel Free, 'Fly' far away!"
type String REP2 = STR.replace("f","F",2)
// Ignore case on lookFor: " Feel Free, 'fly' far away!"
type String REP3 = STR.replace("f","F",2,1)
// Ignore when enclosed by single quote:
// "Feel Free, "fly" Far away!"
type String REP4 = STR.replace("f","F",0,0,"'")