change() Function

The change() 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

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

Synonym(s)

ereplace()

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 change(), 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 = change("The new time","new","old")

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

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

See Also

swap() Function