10 Years of Service
15%
Please note, if you want to make a deal with this user, that it is blocked.
[HIDE-THANKS]
[/HIDE-THANKS]
Code:
>Function SandR (ByVal SearchString As String, ByVal LookFor As String, ByVal ReplaceWith As String) As String
Rem +-----------------------------------------------------------------------+
Rem | SearchString = String to search. |
Rem | LookFor = String to look for within SearchString |
Rem | ReplaceWith = What to replace SearchString |
Rem | |
Rem | Test=SandR("Mary Had a little lamb","a","aa") |
Rem | would return: |
Rem | Maary Haad aa little laamb |
Rem | |
Rem | Compatibility: Visual Basic 2.0 |
Rem | |
Rem | Programmed by: [email protected] |
Rem | |
Rem +-----------------------------------------------------------------------+
Rem +-----------------------------------+
Rem | Declair variables |
Rem +-----------------------------------+
Dim LeftPart As String
Dim RightPart As String
Dim Location As Integer
Dim LeftLocation As Integer
Dim RightLocation As Integer
Rem +-------------------------------+
Rem | Initilize variables |
Rem +-------------------------------+
LeftPart = ""
RightPart = ""
Location = 0
Rem ==========================================================
If Len(LookFor) = 0 Then
LeftPart = SearchString
Else
If LookFor = ReplaceWith Then
LeftPart = SearchString
Else
If Len(SearchString) = 0 Then
LeftPart = SearchString
Else
LeftPart = ""
RightPart = SearchString
Rem ============================================
Do
Location = InStr(1, RightPart, LookFor, 0) ' Case INsensitive
If Location = 0 Then
LeftPart = LeftPart + RightPart
Else
If Location = 1 Then
LeftPart = LeftPart + ReplaceWith
RightLocation = Location + Len(LookFor)
If RightLocation > Len(RightPart) Then
RightPart = ""
Else
RightPart = Mid(RightPart, RightLocation)
End If
Else
If Location >= 2 Then
LeftLocation = Location - 1
RightLocation = Location + Len(LookFor)
LeftPart = LeftPart + Left(RightPart, LeftLocation) + ReplaceWith
If RightLocation > Len(RightPart) Then
RightPart = ""
Else
RightPart = Mid(RightPart, RightLocation)
End If
End If
End If
End If
Loop Until Location = 0
End If
End If
End If
SandR = LeftPart ' Return string
End Function