REPLACE Function

Replaces an attribute, value or subvalue in a dynamic array.

Syntax

REPLACE(dynArray, attr#, value#, subval#, replacement)

or

REPLACE(dynArray, attr#{, value#{, subval#}}; replacement)

Note

The REPLACE function has been replaced by dynamic array references but is maintained here for compatibility.

Syntax Elements

dynArray The name of a dynamic array or variable in which the replacement is made.

attr# The number of the attribute within dynArray.

If you specify a nonzero value for attr# and zero for both value# and subvalue#, the attribute is replaced.

value# The number of the value within the named attribute.

If you specify a nonzero value for both attr# and value# and zero for subvalue#, the value is replaced.

subval# The number of the subvalue within the value.

If you specify nonzero values for attr#, value# and subval#, the subvalue is replaced.

replacement An expression that evaluates to a string containing the replacement value. It cannot contain any system delimiters.

Comments

replacement replaces the specified attribute, value or subvalue, except as follows:

Examples

OPEN 'INVENTORY' ELSE STOP
READ X FROM 'NAME' ELSE STOP
X = REPLACE(X,4,0,0,'EXAMPLE')
WRITE X ON 'NAME'

Replaces attribute 4 of item NAME in file INVENTORY with the string value EXAMPLE.

OPEN '','XYZ' ELSE STOP
READ B FROM 'ABC' ELSE STOP
WRITE REPLACE(B,3,-1,0,'NEW VALUE') ON 'ABC'

Inserts the string value NEW VALUE after the last value of attribute 3 of item ABC in file XYZ.

X=REPLACE(ARR,2,0,0,'')

Replaces attribute 2 of dynamic array ARR with a null string and assigns new array to variable X.

VALUE = "TEST STRING"
DA = REPLACE(DA,4,3,2,VALUE)

Replaces subvalue 2 of value 3 of attribute 4 in dynamic array DA with the string value TEST STRING and assigns the resulting array to DA.

X = "ABC123"
Y = REPLACE(Y,1,1,-1,X)

Inserts the value ABC123 after the last subvalue of value 1 of attribute1 in dynamic array Y.

A=REPLACE(B,2,3,0,"XXX")

Replaces value 3 of attribute 2 of dynamic array B with the value XXX and assigns the resulting array to variable A.