CONVERT function

Syntax

CONVERT (expression1, expression2, variable)

Description

Use the CONVERT function to return a copy of variable with every occurrence of specified characters in variable replaced with other specified characters. Every time a character to be converted appears in variable, it is replaced by the replacement character.

expression1 specifies a list of characters to be converted. expression2 specifies the corresponding replacement characters. The first character of expression2 replaces all instances of the first character of expression1, the second character of expression2 replaces all instances of the second character of expression1, and so on.

If expression2 contains more characters than expression1, the extra characters are ignored. If expression1 contains more characters than expression2, the characters with no corresponding expression2 characters are deleted from the result.

If variable is the null value, null is returned. If either expression1 or expression2 is the null value, the CONVERT function fails and the program terminates with a run-time error message.

The CONVERT function works similarly to the CONVERT statement.

Example

A="NOW IS THE TIME"
PRINT A
A=CONVERT('TI','XY',A)
PRINT A
A=CONVERT('XY','T',A)
PRINT A

This is the program output:

NOW IS THE TIME
NOW YS XHE XYME
NOW S THE TME