Caché MultiValue Basic Reference
Replaces all instances of a substring in a variable.
SWAP oldstring WITH newstring IN variable
||The substring to be replaced. An expression that resolves to a valid string or numeric.
||The replacement substring. An expression that resolves to a valid string or numeric. To delete oldstring, specify the empty string ("").
||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 values of oldstring
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.
Caché MVBasic supports the UniData SWAP
statement for substring replacement. UniVerse implements a completely different SWAP
statement for variable value exchange, which we do not support at this time. Caché MVBasic also supports the UniVerse CHANGE
statement for substring replacement.
both perform string substitution, and are functionally identical. CONVERT
performs character-for-character substitution.
The following example illustrates use of the SWAP
statement, replacing a substring value in all the elements of a dynamic array:
cities="Pittsburg Penn.":@VM:"Philadephia Penn."
SWAP "Penn." WITH "PA" IN cities