a$ = "Visit Microsoft!" 'original string
b$ = "microsoft" 'search string
c$ = "W3Schools" 'replacement string
a$ = "001x002X003x004x005"
b$ = "x"
c$ = "z"
'f$ = "-1"
'f$ = "0"
d$ = replacesub$(a$, b$, c$, d$, e$, f$, g$)
FUNCTION replacesub$
(expression$
, find$
, replacewith$
, start$
, count$
, compare$
, exact$
) IF compare$
= "" THEN compare
= 0 ELSE compare
= VAL(compare$
) 'default is for case sensitve
IF exact$
<> "" THEN 'pad values to isolate whole word find$ = " " + find$ + " "
replacewith$ = " " + replacewith$ + " "
working$ = expression$
start2 = start
tally = 0
rf
= INSTR(start
, working$
, find$
) tmp1$
= MID$(working$
, 1, rf
- 1) 'copy mid$ from start to beginning of found replacement tmp2$
= MID$(working$
, rf
+ rl
) 'then copy from end of replacement to end of the text string (rf + rl) working$ = tmp1$ + replacewith$ + tmp2$
start = rf
rf
= INSTR(start
, working$
, find$
) working$
= MID$(working$
, start2
) replacesub$ = working$
'VB - Replace$(expression, find, replacewith[, start[, count[, compare]]])
'Arguments
'expression
' Required. String expression containing substring to replace.
'find
' Required. Substring being searched for.
'replacewith
' Required. Replacement substring.
'start
' Optional. Position within expression where substring search is to begin. If omitted, 1 is assumed. Must be used in conjunction with count.
'count
' Optional. Number of substring substitutions to perform. If omitted, the default value is -1, which means make all possible substitutions. Must be used in conjunction with start.
'compare
' Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values. If omitted, the default value is 0, which means perform a binary comparison.
'
'if find = "" or replacewith = "" or count = 0 then return expression
'if expression = "" or start > len(expression) return ""