Substitute method: Array class
Syntax
Substitute(old_val, new_val)
Description
The Substitute method replaces every occurrence of a value found in an array with a new value. To replace an element that occurs in a specific location in an array, use Replace.
If the array is one-dimensional, Substitute replaces every occurrence of the old_val in the array with new_val.
If the array is two-dimensional, Substitute replaces every subarray whose first element is equal to old_val, with the subarray given by new_val.
Note:
This method works with arrays that have only one or two dimensions. You receive a runtime error if you try to use this method with an array that has more than two dimensions.
Parameters
| Parameter | Description |
|---|---|
|
old_val |
Specifies the existing value in the array to be replaced. |
|
new_val |
Specifies the value with which to replace occurrences of old_val. |
Returns
None
Example
The following example changes the array &A to be ("John", "Jane", "Hamilton" ).
&A = CreateArray();
&A[1] = "John";
&A[2] = "Jane";
&A[3] = "Henry";
&A.Substitute("Henry", "Hamilton");
The following example changes the array &A to be (("John", 1952), ("Jane", 1957), ("Hamilton", 1971), ("Frank", 1961)).
&A = CreateArray(CreateArray("John", 1952), CreateArray("Jane", 1957), CreateArray⇒
("Henry", 1928), CreateArray("Frank", 1961));
&A.Substitute("Henry", CreateArray("Hamilton", 1971));
Related Topics