Creator Help

replaceAll

This topic describes the syntax and usage of the replaceAll function in Zoho Creator .

Description

The replaceAll function replaces all occurrence of the string that matches the given <searchString> expression with the given <replacementString>

Syntax

<string>.replaceAll(searchString, replacementString, [escapeRegEx])

(or)

replaceAll(string, searchString, replacementString, [escapeRegEx])

// this format is supported only in the free flow scripting mode of Script builder.

The replaceAll function syntax has the following arguments.

string - Required. The main string

searchString - Required. The substring to be searched for in the main string

replacementString - Required. The replacement substring

By default, the replaceAll() function supports regular expression (i.e) it will not find and replace the special characters like $,* etc., in the source string. The parameter [escapeRegEx] is an optional boolean parameter provided to specify if the regular expression is to be supported or escaped by Zoho Creator, while executing the replaceAll() function.

  • The value true denotes escaping the regular expression support on replace functions.
  • The value false denotes supporting regular expression on replace functions. By default, the value is  taken as "false".

Note: If the value for escapeRegEx parameter is not specified, the value we will take as " false". i.e By default, regular expression is supported on replace functions. For example, the following two functions will perform the same operation:

 

replaceAll("Create online database applications", "online","custom",false);
replaceAll("Create online database applications", "online","custom");

Return Value

Returns the replaced string.

Example

mainString="Jack and Jill went up the hill to fetch a pail of water";
searchString="Jack";
replacementString="Bill";

mainString.replaceAll(searchString,replacementString);        //returns "Bill and Jill went up the hill to fetch a pail of water"

 

Address = "Suite 123, 4523 Yonge Street, Toronto"; 
Address.replaceAll("23","9945");         //returns "Suite 19945, 459945 Yonge Street, Toronto"



mainString="Jack and Jill went up the hill to fetch a pail of water";
searchString="Jack";
replacementString="Bill";

replaceAll(mainString,searchString,replacementString);        //returns "Bill and Jill went up the hill to fetch a pail of water"

 

Address = "Suite 123, 4523 Yonge Street, Toronto"; 
replaceAll(Address,"23","9945");         //returns "Suite 19945, 459945 Yonge Street, Toronto"



Top