CHANGE Function

Replaces a substring with a new substring.

Syntax

CHANGE(old-string, old-substr, new-substr)

Syntax Elements

old-string is the original string.

old-substr is the substring in the original string to be changed.

new-substr is the replacement substring.

Comments

All occurrences of old-substr in old-string are replaced by new-substr.

The parameters old-string, old-substr and new-substr can be any expression, such as a variable or symbol name, literal string in quotes, array element or other DataBasic expression.

See Also

CONVERT function, CONVERT statement.

Examples

OLDSTR = "IRVINE, CA 92714"
A = "92714"
B = "92720"
NEWSTR = CHANGE(OLDSTR, A,B)

Replaces substring A (92714) in OLDSTR with substring B (92720) and assigns the new value to NEWSTR. NEWSTR contains IRVINE, CA 92720.

X = "31AA42BB53AAA"
Y = "AA"
Z = "CC"
NEWVALUE = CHANGE(X,Y,Z)

Changes the value of 31AA42BB53AAA to 31CC42BB53CCA.

MESSAGE = "Unable to open file ***"
.
.
OPEN GUESTS TO GUESTS ELSE
    PRINT CHANGE(MESSAGE,"***","GUESTS")
END

If the program is unable to open the GUESTS file, it branches to the ELSE clause to print the new string generated by the CHANGE function. The CHANGE function generates a new string by taking the string assigned to message and replacing the dummy asterisks *** with the GUESTS file name.

Go to top button