Documentation Comments
Use this form to comment on this topic. You can also provide any general observations about the Online Documentation, or request that additional information be added in a future release.
Reality V15.0 ()
CHANGE Function (DataBasic) (m618703+change_f.htm)
Replaces a substring with a new substring.
CHANGE(oldString, oldSubstr, newSubstr{, count{, startOccur}})
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.
CHANGE returns the modified string.
The parameters oldString, oldSubstr and newSubstr can be any expressions that evaluate to strings.
If data case insensitive mode is selected (see Case Sensitivity), case is ignored when searching oldString for oldSubstr.
CONVERT function, CONVERT statement.
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.