The SUBSTITUTE function returns a string value where the specified characters of a given string value have been replaced with a new string value.
SUBSTITUTE(source-string, existing-string, new-string, occurrence)
source-string: Any value.
existing-string: The value to be replaced. existing-string can contain any value.
new-string: The value used as a replacement. new-string can contain any value. It does not have to be the same length as existing string.
occurrence: An optional number value specifying which occurrence of existing-string within source-string should be replaced. occurrence must be greater than or equal to 1, or omitted. If occurrence is greater than the number of times existing-string appears within source-string, no replacement will occur. If occurrence is omitted, all occurrences of existing-string within source-string will be replaced by new-string.
Notes
You can replace individual characters, whole words, or strings of characters within words.
Examples |
|---|
=SUBSTITUTE(“a b c d e f”, “b”, “B”) returns “a B c d e f”. =SUBSTITUTE(“a a b b b c”, “a”, “A”, 2) returns “a A b b b c”. =SUBSTITUTE(“a a b b b c”, “b”, “B”) returns “a a B B B c”. =SUBSTITUTE(“aaabbccc”, “bc”, “BC”, 2) returns “aaabbccc”. =SUBSTITUTE(60606, 6, 3) returns “30303”. |