LOTUSSCRIPT LANGUAGE


ArrayReplace function
Performs a search and replace routine for multiple values within an array.

Syntax

ArrayReplace( sourceArray, compareArray, replaceArray )

Elements

sourceArray


compareArray
replaceArray
Return value

A Variant containing an array which is constructed by these rules (the answer array).

Usage

Each element in sourceArray is prepared to be copied into the answer array. The resulting array is the same size as the array contained in parameter sourceArray. If the source and replace arrays are arrays of matching types, the answer array will be of that type. Otherwise, the answer array will be an array of Variants.

Note ArrayReplace works only with these LotusScript scalar data types: integer, long, single, double, currency, string, boolean, and byte. If any other data type is used in the sourceArray or the replaceArray, the resulting array contains the exact same data elements as the sourceArray; that is, no replacement of array elements occurs.

For each element in sourceArray, compareArray is scanned. If no elements match, the element from sourceArray is copied into the next available index in the answer array. However, if an element of compareArray matches an element from sourceArray, the index of the compareArray element is used to find a value in the array replaceArray. This value is then copied into the answer array instead of the value from sourceArray.

For example:


If the index from compareArray cannot be used as an index into replaceArray (that is, the index is out of bounds), a 0 or type equivalent is copied into the answer array for that element.

Indices into the arrays are calculated from their base. Assume that compareArray is an array from (-10 to 0), and replaceArray is an array from (1 to 5). If the -10th element of compareArray, which is the first element in that array, is a match for a given element in sourceArray, then the first element of replaceArray is used as a replacement.

For example:


Each element type must match for a conversion to take place. For example, if sourceArray contains the value 1 of data type integer, and compareArray contains the value 1 of data type long, then these elements would not match.

Extended examples: array and String functions

See Also