by C. Benjamin bostic (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 3rd February 1999
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
This function recieves three strings: strSearch - string to search in, strOld - string to look for, and strNew - string to replace strOld
strOld As String, _
strNew As String) As String
Dim lngFoundPos As Long
Dim strReturn As String
Dim strReplace As String
Dim strIn As String
Dim strFind As String
Dim lngStartPos As Long
strIn = strSearch
strFind = strOld
strReplace = strNew
lngFoundPos = 1
lngStartPos = 1
strReturn = ""
'Process the string while strFind is found
Do While lngFoundPos <> 0
lngFoundPos = InStr(lngStartPos, strIn, strFind)
'If strFind is found
If lngFoundPos <> 0 Then
'Take all characters before strFind, add strReplace
'onto the end, and add this to strReturn
strReturn = strReturn & _
Mid$(strIn, lngStartPos, lngFoundPos - lngStartPos) & _
strReplace
'If no strFind is found
Else
'Add the remainder of the string to strReturn
strReturn = strReturn & _
Mid$(strIn, lngStartPos)
End If
'Start next search at the first character after the replaced string
lngStartPos = lngFoundPos + Len(strFind)
Loop
'Return the new string
gfReplaceString = strReturn
End Function
No comments have been posted about This function recieves three strings: strSearch - string to search in, strOld - string to look for,. Why not be the first to post a comment about This function recieves three strings: strSearch - string to search in, strOld - string to look for,.