VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

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

Mohannad Sulaiman Abu Sall  (4 Submissions)   String Manipulation   VB 6.0   Unknown Difficulty   Sun 22nd September 2002   Mon 8th February 2021

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 (1(1 Vote))
Two functions: first to find one string within another, and the other to replace one string with an.bas

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

No comments yet — be the first to post one!

Post a Comment

0/1000 characters