Replace

This function replaces a specified substring with another specified substring a specified number of times.

Syntax

Replace(expression, find, replacewith, [start], [count], [compare])

Parameters

expression
Required. String expression that contains a substring to replace.
find
Required. Substring being searched for.
replacewith
Required. Replacement substring.
start
Optional. Position within expression where substring search begins. If omitted, 1 is assumed.
count
Optional. Number of substring substitutions to perform. If omitted, the default value is –1, which means make all possible substitutions.
compare
Optional. Numeric value that indicates the kind of comparison to use when evaluating substrings. The following table shows the possible values for the compare parameter.
Constant
Value
Description
vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Perform a textual comparison.
vbDatabaseCompare 2 Not supported

Return Values

The following table shows the return values for the Replace function.

If
Replace returns
expression is zero-length A zero-length string ("")
expression is Null An error
find is zero-length A copy of expression
replacewith is zero-length A copy of expression with all occurrences of find removed
start > Len(expression) A zero-length string
count is 0 A copy of expression

Remarks

The return value of Replace is a string, with substitutions made, that begins at the position specified by start and concludes at the end of the expression string. It is not a copy of the original string from start to finish.