by Danny Hawkins (1 Submission)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 25th September 2002
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
String replace function
' Function to replace a string within a string
' srchStr string is the text to look in
' forStr is the string to search for
' repStr is the string to replace any occurences of forStr
*
'
'THIS FUNCTION IS CASE SENSITIVE
'
' Example:
' MyString = Replace("Hello world!","Hello","Goodbye")
'
' This would make MyString "Goodbye world!"
'
' D.Hawkins 2002
Public Function Replace(srchStr, forStr, repStr)
If InStr(srchStr, forStr) Then
Do While InStr(srchStr, forStr)
place = InStr(srchStr, forStr)
srchStr = Mid(srchStr, 1, place - 1) & repStr & Mid(srchStr, place + Len(forStr), Len(srchStr))
Replace = srchStr
Loop
Else
Replace = srchStr
End If
End Function