convert() function

The convert() function searches a given variable and replaces each occurrence of a character by another.

Syntax

 result = convert(var, str.exp1, str.exp2)

Parameter(s)

var Variable in which the specified string will be searched and replaced.
str.exp1 Specifies the characters to be replaced with the corresponding replacement characters from str.exp2.
str.exp2 Specifies the characters to replace the characters specified in str.exp1.

Description

The original string is not modified unless it is also specified as the result string.

Any character designated in str.exp1 is replaced with the corresponding replacement character from str.exp2. The correspondence is by column position in str.exp1 and str.exp2.

  • If the length of str.exp1 is shorter than str.exp2, all characters in str.exp2 beyond the length of str.exp1 are ignored.
  • If the length of str.exp1 is longer than str.exp2, all characters in str.exp1 beyond the length of str.exp2 are deleted from the result.

Example(s)

Example 1
 * convert commas to attribute marks
 var = "a,b,c"
 str.exp1 = ","
 str.exp2 = @AM
 result = convert( var, str.exp1, str.exp2 )
 crt "var = " : var
 crt "result = " : result

Example 2
 * convert commas to dots, and dots to commas
 var = "12,345,678.90"
 str.exp1 = ",."
 str.exp2 = ".,"
 result = convert( var, str.exp1, str.exp2 )
 crt "var = " : var
 crt "result = " : result