searching a text file

grizzlyjdw2

Registered User.
Local time
Today, 04:58
Joined
Feb 26, 2009
Messages
22
ok, here is my code to search the text file itself

Public Function StringExistsInFile(ByVal TheString As String, ByVal TheFile As String) As Boolean
Dim L As Long, S As String, FileNum As Integer
FileNum = FreeFile
'MsgBox TheString
'MsgBox TheFile

Open TheFile For Binary Access Read Shared As #FileNum
L = LOF(FileNum)
S = Space$(L)
Get #1, , S
Close #FileNum
If InStr(1, S, TheString, vbBinaryCompare) Then

StringExistsInFile = True
End If
'MsgBox StringExistsInFile

End Function

works great and is fast, but just one small problem. is there anyway to search the file for whole words only? for example if i have the word "network" and search for "work", it returns a true. thanks ahead of time :)
 
How about appending a space on the front and the end of the search term?
 
that way acutally gets rid of some of my positive searches.

i think what i am going to have to do is take the position returned by InStr and check the spot in the string before and the spot after the search phrase to see if they are spaces or not.

that should allow whole case matches only.....hopefully :)
 
Yes. Adding the spaces to the search string would miss the first word in the paragraph and the last word in a sentence.
 

Users who are viewing this thread

Back
Top Bottom