' Replace all occurrances of from_str with to_str.
Public Function ReplaceText(ByVal txt As String, ByVal _
from_str As String, ByVal to_str As String) As String
Dim result As String
Dim from_len As Integer
Dim pos As Integer
from_len = Len(from_str)
Do While Len(txt) > 0
' Find from_str.
pos = InStr(txt, from_str)
If pos = 0 Then
' No more occurrences.
result = result & txt
txt = ""
Else
' Make the replacement.
result = result & Left$(txt, pos - 1) & to_str
txt = Mid$(txt, pos + from_len)
End If
Loop
ReplaceText = result
End Function
|