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.
change(str.exp, search.str, replacement.str{,occurrences{,start}})
ereplace() swap()
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. |
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)