str3

 

Implement Search And Replace All (VB 6.0 And Above)


Implement Search And Replace All (VB 6.0 And Above)

Search for all the appearances of specific substring within other string,
and replace them all with new substring. This code uses the Split
function that available only in VB 6.0 and above.

Form Code

Function ReplaceAll(SourceString As String, ReplaceThis As String,
WithThis As String)
Dim Temp As Variant
Temp = Split(SourceString, ReplaceThis)
ReplaceAll = Join(Temp, WithThis)
End Function

Private Sub Form_Load()
'the example below replace all the "go" substrings with "bad",
'in the string "good boy go home"
MsgBox ReplaceAll("good boy go home", "go", "bad")
End Sub