- Home
·
- String Manipulation
·
- This function recieves three strings: strSearch - string to search in, strOld - string to look for,
This function recieves three strings: strSearch - string to search in, strOld - string to look for,
This function recieves three strings: strSearch - string to search in, strOld - string to look for, and strNew - string to replace strOld
Rate This function recieves three strings: strSearch - string to search in, strOld - string to look for,
(1(1 Vote))
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
This function recieves three strings: strSearch - string to search in, strOld - string to look for, Comments
No comments yet — be the first to post one!
Post a Comment