VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Two functions: first to find one string within another, and the other to replace one string with an

by Mohannad Sulaiman Abu Sall (4 Submissions)
Category: String Manipulation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 22nd September 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Two functions: first to find one string within another, and the other to replace one string with another

API Declarations



Public Enum CaseSensetive
CapitalLetter = 0
SmallLetter = 1
SameYouWrite = 2
Normal = 3
End Enum

Function FindString(FromString As String, SearchString As String, WordCase As CaseSensetive) As Boolean
Dim I As Long
Dim Cut As String

Select Case WordCase
Case 0
For I = 1 To Len(FromString)
Cut = Mid$(FromString, I, Len(SearchString))
If UCase(Cut) = SearchString Then
FindString = True
Exit For
Else
FindString = False
End If
Next
Case 1
For I = 1 To Len(FromString)
Cut = Mid$(FromString, I, Len(SearchString))
If LCase(Cut) = SearchString Then
FindString = True
Exit For
Else
FindString = False
End If
Next
Case 2
For I = 1 To Len(FromString)
Cut = Mid$(FromString, I, Len(SearchString))
If LCase(Cut) = LCase(SearchString) Then
FindString = True
Exit For
Else
FindString = False
End If
Next
Case 3
For I = 1 To Len(FromString)
Cut = Mid$(FromString, I, Len(SearchString))
If Cut = SearchString Then
FindString = True
Exit For
Else
FindString = False
End If
Next
End Select

End Function

Function ReplaceWith(FromString As TextBox, SearchStr As String, ReplaceWithStr As String, WordCase As CaseSensetive) As Boolean
Dim I As Long
Dim Cut As String

Select Case WordCase
Case 0
For I = 1 To Len(FromString.Text)
Cut = Mid$(FromString.Text, I, Len(SearchStr))
If LCase(Cut) = LCase(SearchStr) Then
FromString.SelStart = I - 1
FromString.SelLength = Len(SearchStr)
FromString.SelText = UCase$(ReplaceWithStr)
ReplaceWith = True
Exit For
Else
ReplaceWith = False
End If
Next
Case 1
For I = 1 To Len(FromString.Text)
Cut = Mid$(FromString.Text, I, Len(SearchStr))
If LCase(Cut) = LCase(SearchStr) Then
FromString.SelStart = I - 1
FromString.SelLength = Len(SearchStr)
FromString.SelText = LCase$(ReplaceWithStr)
ReplaceWith = True
Exit For
Else
ReplaceWith = False
End If
Next
Case 2
For I = 1 To Len(FromString.Text)
Cut = Mid$(FromString.Text, I, Len(SearchStr))
If LCase(Cut) = LCase(SearchStr) Then
FromString.SelStart = I - 1
FromString.SelLength = Len(SearchStr)
FromString.SelText = ReplaceWithStr
ReplaceWith = True
Exit For
Else
ReplaceWith = False
End If
Next
Case 3
For I = 1 To Len(FromString.Text)
Cut = Mid$(FromString.Text, I, Len(SearchStr))
If LCase(Cut) = LCase(SearchStr) Then
FromString.SelStart = I - 1
FromString.SelLength = Len(SearchStr)
FromString.SelText = ReplaceWithStr
ReplaceWith = True
Exit For
Else
ReplaceWith = False
End If
Next
End Select

End Function


Rate Two functions: first to find one string within another, and the other to replace one string with an




Download this snippet    Add to My Saved Code

Two functions: first to find one string within another, and the other to replace one string with an Comments

No comments have been posted about Two functions: first to find one string within another, and the other to replace one string with an. Why not be the first to post a comment about Two functions: first to find one string within another, and the other to replace one string with an.

Post your comment

Subject:
Message:
0/1000 characters