Replace function (LotusScript® Language)

Replaces specific words or phrases in a string with new words or phrases that you specify.

Syntax

Replace( source, find , replacement [, start [, count [, compMethod]]])

Elements

source

String, or Array of type String containing the strings to be modified

find

String, or Array of type String containing the words or phrases to be replaced

replacement

String, or Array of type String containing the replacement words or phrases

start

optional Integer specifying the character position to start at in each String

count

optional Integer specifying the maximum number of replacements to make.

compMethod

Optional Integer specifying the type of comparison to use when searching for the delimiter, if the elements are strings.

Number

Comparison Mode

0

case sensitive, pitch sensitive

1

case insensitive, pitch sensitive

4

case sensitive, pitch insensitive

5

case insensitive, pitch insensitive

If you omit compMethod, the default comparison mode is the mode set by the Option Compare statement for this module. If there is no statement for the module, the default is case sensitive and pitch sensitive.

Return value

Replace returns an Array of type String that contains sourceArray, where any values in replaceArray have been replaced by the corresponding values in replacementArray.

Usage

Replace searches the String in sourceArray for the String in replaceArray. If a match is found, the substring is replaced with a corresponding substring from replacementArray. Each String in replaceArray is scanned against each String in sourceArray as modified by prior substitutions. Replace is case sensitive.

If no matches are found, then a copy of sourceArray is returned.

If more strings are specified in replaceArray than in replacementArray, the extra strings in replaceArray are replaced with the last string in replacementArray. Extra strings in replacementArray are ignored.

For example:

sourceArray = ["first second third"]
replaceArray = ["first"]["second"]["1"]["third"]["2"]["3"]
replacementArray = ["1"]["2"]["a"]["3"]["b"]["c"]

would return: ["a b c"]

First, Replace substitutes "1" for "first" (the first String in replacementArray replaces the first string in replaceArray):

["1 second third"]

Then Replace substitutes "2" for "second":

["1 2 third"]

Then "a" for "1" (since the first replacement was "1" for "first"):

["a 2 third"]

Then "3" for "third":

["a 2 3"]

"b" for "2":

["a b 3"]

And finally, "c" for "3":

["a b c"]

If sourceArray, replaceArray, or replacementArray is not either a String, or an Array of type String, then a run-time type mismatch error is thrown.

Example