ereplace() function

The ereplace() function searches a string expression for the search string and then, if at the start occurrence, replaces search.str with replacement.str for the amount of occurrences specified in occurrences.

Syntax

ereplace(str.exp, search.str, replacement.str{,occurrences{,start}})

Synonym(s)

change()
swap()

Parameter(s)

str.exp String in which the specified search.str is searched for.
search.str String to search for in str.exp.
replacement.str String to replace the specified search.str.
occurrences Specifies the number of occurrences of search.str to be replaced by replacement.str. If not specified, defaults to 0, which replaces all found occurrences.
start Specifies which occurrence of search string the replacement begins. If not specified, defaults to 1.

Description

Note: To use ereplace(), it is necessary to use a nondefault compiler compatibility option. Inserting the $options ext statement at the beginning of the program accomplishes this.

Example(s)

Assigns the value "The old time" to nstring.

$options ext
nstring = ereplace("The new time","new","old")

This outputs "++-". The ereplace() function replaces one occurrence of "-" starting at the second occurrence.

print ereplace("---","-","+",2,1)