Caché MultiValue Basic Reference
CONVERT
|
|
Replaces single characters in a string.
Synopsis
CONVERT(remove,replace,string)
The
CONVERT function edits the value of
string by replacing all instances of each single character in
remove with the corresponding single characters in
replace and returning the resulting string.
CONVERT performs a character-for-character substitution. Matching of characters is case-sensitive.
-
-
To replace all instances of a character in a string with another character, specify the character to be replaced in
remove and the replacement character in
replace. For example, to replace all instances of the # character with the * character in
mystring:
CONVERT("#","*",mystring)
-
To replace all instances of a list of single characters with corresponding other single characters, specify those characters to be replaced in
remove and the corresponding replacement characters in
replace. For example, to replace all instances in
mystring of the each lowercase letter a, b, c, and d with the corresponding uppercase letter:
CONVERT("abcd","ABCD",mystring)
-
To both replace some single characters and remove others, specify those characters to be replaced or removed in
remove. First specify those to be replaced, then those to be removed. Specify the corresponding replacement characters in
replace, and nothing for the characters to be removed. For example, to replace all instances of + with &, and to remove all instances of # in
mystring:
CONVERT("+#","&",mystring)
The value of
remove and
replace 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
CONVERT operation.
If
remove contains more characters than
replace, the unpaired characters are deleted from the returned string. If
replace contains more characters than
remove, the unpaired characters are ignored and have no effect.
Note:
CONVERT performs single character one-for-one substitution for all instances in a string. The
CHANGE function performs substring replacement, and can specify how many instances to replace and where to begin replacement.
The
CONVERT statement and the
CONVERT function perform the same operation, with the following difference: the
CONVERT statement changes the supplied string; the
CONVERT function returns a new string with the specified changes and leaves the supplied string unchanged.
The order of the
CONVERT arguments differs in different emulation modes. In Caché MVBasic, the order is
remove,replace,string. In MultiValue emulation modes, the argument order is as follows:
The following example illustrates use of the
CONVERT function in converting a string to a dynamic array by replacing the # character with a Value Mark level delimiter character:
cities="New York#Chicago#Boston#Los Angeles"
dynacities=CONVERT("#",CHAR(253),cities)
PRINT cities
PRINT dynacities