Replace

Replaces occurrences of substring1 in a string with substring2, in a specified scope. The search is case-sensitive.

Replace( string, substring [, replacement [, scope ] ] )

Returns: String

Argument Description Default
string
string, required

String in which to search.

substring
any, required

Substring for which to search. Optionally pass a Struct with key/value pairs to do a replace all

Alias: sub1, find, substring1

replacement
any, optional

Substring with which to replace the found matches. This arg is required if the substring1 arg is a string

Alias: sub2, repl, substring2

scope
string, optional

scope for the execution:

  • one (default): replaces only the first occurrence
  • all: replaces all occurrences

one

Examples

writeDump(replace("xxabcxxabcxx","abc","def"));
writeDump(replace("xxabcxxabcxx","abc","def","All"));
writeDump(replace("abc","a","b","all"));
writeDump(replace("a.b.c.d",".","-","all"));
test = "camelcase CaMeLcAsE CAMELCASE";
test2 = Replace(test, "camelcase", "CamelCase", "all");
writeDump(test2);

See also