substitute
Replaces one or more text strings with another text string.
Parameters
S (string)
The input string.
OLD (string)
The text to replace.
NEW (string)
The replacement text.
I (number)
Optional. How many instances of old text to replace.
Default: all instances
Examples
[[ myString = 'The drivers are sales of Retine (increase 6.2%) and Glower (increase 5.3%).' substitute(myString, 'increase', 'up') ]]
The output string:
The drivers are sales of Retine (up 6.2%) and Glower (up 5.3%).
The fourth parameter specifies the number of replacements:
[[ myString = 'The drivers are sales of Retine (increase 6.2%) and Glower (increase 5.3%).' substitute(myString, 'increase', 'up', 1) ]]
The output string:
The drivers are sales of Retine (up 6.2%) and Glower (increase 5.3%).
Note
The fourth parameter is set to 1, so only the first increase is replaced.
If the function has three values to replace and finds only two, it returns the input string unchanged:
[[ myString = 'The drivers are sales of Retine (increase 6.2%) and Glower (increase 5.3%).' substitute(myString, 'increase', 'up', 3) ]]
The output string:
The drivers are sales of Retine (increase 6.2%) and Glower (increase 5.3%).