REPLACE()

REPLACE()

Top  Previous  Next

 

The REPLACE() function replaces a field, value or subvalue of a dynamic array, returning the result.

 

 

Format

 

REPLACE(dyn.array, field {, value {, subvalue}} , string)

 

where

 

dyn.arrayevaluates to a string in which the replacement is to occur.

 

fieldevaluates to the field position number. If zero, this argument defaults to one.

 

valueevaluates to the value position number. If omitted or zero, the entire field is replaced.

 

subvalueevaluates to the subvalue position number. If omitted or zero, the entire value is replaced.

 

stringevaluates to the replacement data.

 

If field, value and subvalue are not all present, the comma before the string argument must be replaced by a semicolon.

 

The statement

S = REPLACE(S, F, V, SV, NEW)

is equivalent to

S<F, V, SV> = NEW

 

If the specified field, value or subvalue is not present in the dyn.array, mark characters are added and the new item is inserted.

 

A negative value of field, value or subvalue causes a new field, value or subvalue to be appended. The lower ranking items are taken as being one. For example,

S = REPLACE(X, -1, 2, 3, Z)

appends a new field. The value and subvalue arguments are treated as though the statement were

S = REPLACE(X, -1, 1, 1, Z)

 

See the description of the S<f,v,sv> assignment operator for a discussion of how QM appends items, in particular with regard to the COMPATIBLE.APPEND option of the $MODE compiler directive.

 

 

Example

 

S = REPLACE(REC, 3, 1; ITEM)

 

This statement assigns S with the result of replacing field 3, value 1 of REC by the contents of ITEM. The value of REC is not changed.

 

 

See also:

DEL, DELETE(), EXTRACT(), FIND, FINDSTR, INS, INSERT(), LISTINDEX(), LOCATE, LOCATE()