SUBSTITUTE (OriginalText, OldText, NewText, Which?) SUBSTITUTE (OriginalText; OldText; NewText; Which?)

OriginalText

Text Text

The original text string.

OldText

Text Text

The text string to be replaced.

NewText

Text Text

The replacement text.

Which

Number Number (optional)

A number which specifies which occurrence of the second parameter to replace (counting from the left). If omitted, every occurrence is replaced.

Returns

Text Text

The resulting text string.

Substitutes new text for old text in a text string and returns it. SUBSTITUTE ("abc def", "def", "xyz") SUBSTITUTE ("abc def"; "def"; "xyz") returns "abc xyz", a version of the first parameter where all occurrences of the second parameter, "def", have been replaced by the third parameter, "xyz".

Use REPLACE to replace text where the position of the text to be replaced is known. Use REGEXREPLACE to replace text using powerful regular expressions which find the text to replace.

Examples

SUBSTITUTE ("abc def", "def", "xyz")
SUBSTITUTE ("abc def"; "def"; "xyz")

Returns "abc xyz".

SUBSTITUTE ("a-b-c", "-", "+")
SUBSTITUTE ("a-b-c"; "-"; "+")

Returns "a+b+c", as every occurrence is replaced when the Which parameter is omitted.

SUBSTITUTE ("a-b-c", "-", "+", 2)
SUBSTITUTE ("a-b-c"; "-"; "+"; 2)

Returns "a-b+c", as only the second occurrence is replaced.

REGEXREPLACE ("abc def", "d\w\w", "xyz")
REGEXREPLACE ("abc def"; "d\w\w"; "xyz")

Returns "abc xyz". The regular expression "d\w\w" matches a literal "d", followed by exactly two letters, thereby matching "def".

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell