EREPLACE function

Syntax

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

Description

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

occurrence specifies the number of occurrences of substring to replace. To replace 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, replacement is prefixed to expression. 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 EREPLACE function fails and the program terminates with a run-time error message.

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

Example

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

This is the program output:

AAAZZZCCCDDDZZZ
ZZZAAABBBCCCDDDBBB
AAACCCDDD