Creator Help

replaceFirst

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

Description

The replaceFirst function replaces the first occurrence of the string that matches the given <searchString> expression with the given <replacementString>. 

Syntax

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

(or)

replaceFirst(string, searchString, replacementString, [escapeRegEx]
// this format is supported only in the free flow scripting mode of Script builder.

The replaceFirst 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 replaceFirst() 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".

Return Value

Returns the replaced string.

Example

replaceFirst("abcabcabc", "ab", "x");   //returns xcabcabc

"abcabcabc".replaceFirst( "ab", "x");   //returns xcabcabc

Top