CHANGE function

Syntax

CHANGE (expression, substring, replacement [ ,occurrence [ ,begin] ] 
)

Description

Use the CHANGE function to replace a substring in expression with another substring. If you do not specify occurrence, each occurrence of the substring is replaced.

occurrence specifies the number of occurrences of substring to replace. To change all occurrences, specify occurrence as a number less than 1.

begin specifies the first occurrence to replace. If begin is omitted or less than 1, it defaults to 1.

If substring is an empty string, the value of expression is returned. If replacement is an empty string, all occurrences of substring are removed.

If expression evaluates to the null value, null is returned. If substring, replacement, occurrence, or begin evaluates to the null value, the CHANGE function fails and the program terminates with a run-time error message.

The CHANGE function behaves like the EREPLACE function except when substring evaluates to an empty string.

Example

A = "AAABBBCCCDDDBBB"
PRINT CHANGE (A,"BBB","ZZZ")
PRINT CHANGE (A,"","ZZZ")
PRINT CHANGE (A,"BBB","")

This is the program output:

AAAZZZCCCDDDZZZ
AAABBBCCCDDDBBB
AAACCCDDD