Skip to main content


Replaces all instances of a substring in a variable.


CHANGE oldstring TO newstring IN variable


oldstring The substring to be replaced. An expression that resolves to a valid string or numeric.
newstring The replacement substring. An expression that resolves to a valid string or numeric. To delete oldstring, specify the empty string ("").
variable An existing variable containing a string value. variable may be a dynamic array. variable accepts a single dynamic array reference (A<i>), a single substring reference (A[s,l]), or a substring reference nested inside a dynamic array reference (A<i>[s,l]).


The CHANGE statement edits the value of variable by replacing all instances of oldstring with newstring. The oldstring and newstring values may be of different lengths. Matching of strings is case-sensitive. If oldstring is not present in the variable, no operation is performed.

The values of oldstring and newstring can be a string or a numeric. If numeric, the value is converted to canonical form (plus sign, leading and trailing zeros removed) before performing the string replacement.

To remove all instances of oldstring from variable, specify the null string ("") as the newstring value. The null string ("") cannot be used as the oldstring value.

CHANGE and SWAP both perform string substitution, and are functionally identical. CONVERT performs character-for-character substitution.


In following example, CHANGE replaces every instance of “?” with “[PLEASE CHECK]” in global variable ^mytest:

^mytest="Jones":@VM:"?":@VM:"? Water St.":@VM:"Springfield":@VM:"?"
PRINT ^mytest 

See Also

FeedbackOpens in a new tab