REPLACE function

REPLACE(OriginalText, StartIndex, Length, NewText) REPLACE(OriginalText; StartIndex; Length; NewText)

OriginalText

Text or { Text }

The original text string.

StartIndex

Number or { Number }

The position in the originalText text string where the newText text string should be inserted.

Length

Number or { Number }

The number of characters that should be replaced.

NewText

Text or { Text }

The replacement text string.

Returns

Text or { Text }

The resulting text string.

Replaces a part of a text string with a different text string and returns the result. REPLACE("one two three", 5, 3, "2")REPLACE("one two three"; 5; 3; "2") returns "one 2 three". The second parameter, 5, is the position where "two" starts, and the third parameter, 3, is the length of the text string to replace, "two". The fourth parameter is the replacement text string.

Use SUBSTITUTE to replace text where the text to be replaced is known, but not its position. Use REGEXREPLACE to replace text using powerful regular expressions which find the text to replace.

Examples

REPLACE("one two three", 5, 3, "2")REPLACE("one two three"; 5; 3; "2")

Returns "one 2 three".

REPLACE("one two three", 5, 3, { "2", "TWO" })REPLACE("one two three"; 5; 3; { "2"; "TWO" })

Returns the array { "one 2 three", "one TWO three" }{ "one 2 three"; "one TWO three" }.