Investment Studio > Expressions > Functions > Text > SUBSTITUTE

string substitute(string in_string, string old_string, string new_string, integer instance_number)

Returns in_string with occurrence number instance_number of old_string replaced with new_string.

If instance_number is omitted, all occurrences of old_string are replaced with new_string.

Examples

=substitute("Stock Quote Stock", "Stock", "Bond")

equals "Bond Quote Bond" (all occurrences of "Stock" replaced with "Bond")

=substitute("Quarter 2, 2002", "2", "1", 1)

equals "Quarter 1, 2002" (first occurrence of "2" replaced with "1")

=substitute("Quarter 2, 2002", "2", "1", 3)

equals "Quarter 2, 2001" (third occurrence of "2" replaced with "1").

See also clean, find, left, mid, replace, right, search, trim.