CHANGE Function

Replaces a substring with a new substring.

Syntax

CHANGE(oldString, oldSubstr, newSubstr{, count{, startOccur}})

Syntax Elements

oldString The original string.

oldSubstr The substring in the original string to be changed.

newSubstr The replacement substring.

count The number of occurrences of oldSubstr to replace with newSubstr. If omitted or less than 1, all occurrences are replaced.

startOccur The number of the first occurrence to replace. If omitted or less than 1, the first occurrence is assumed.

Return Value

CHANGE returns the modified string.

Comments

The parameters oldString, oldSubstr and newSubstr can be any expressions that evaluate to strings.

Case Insensitivity

If data case insensitive mode is selected (see Case Sensitivity), case is ignored when searching oldString for oldSubstr.

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 "31AA42BB53AAA" to "31CC42BB53CCA" and sets NEWVALUE to the result.

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

Changes "31AA42BB53AAA" to "31CC42BB53AAA" and sets NEWVALUE to the result. The second occurrence of "AA" is not changed because only one occurrence is changed.

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

Changes "31AA42BB53AAA" to "31AA42BB53CCA" and sets NEWVALUE to the result. The first occurrence of "AA" is not changed because replacement starts at the second occurrence.

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.