Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search for all "hello" stings in a big big file 2

Status
Not open for further replies.

Madz

Technical User
Jan 31, 2001
33
0
0
SE
And then print out which row the "hello" word is on?

Thanks in advance!
 
Since you mention "Row", i 'assune' that the 'file' is a (table type) recordset? Then, would I need to further assume that the word of interest 'Hello' is a sample? then I would be forced to ask if the task was to find the word in a single field, or a specific set of fields or just generically anywhere in the record? Finally - at least for this scenario - I would want to know what constitutes the 'which row'? Do you want the row (as in the entire record) the row identifier (primary key | Autonumber | ...)

Alas/alack if the "File" is not a recordset, then some additional inquiries need to be made, such as what constitutes a "row" in the file format?
MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
I have a huge File ~1 Gb that I want to read and find out how much data there is between for example: "hello" and the other statement "hello"

The file contains only of plain text and I want to print out on which row there "hello" are on.

Many thanks!
 
You have a 1GB Text File?!OK . . . searching isn't going to be that hard, but it will be slow. The only question I would have for you in how are the "rows" seperated? Is it using a standard carriage row & line feed combination? - Jeff Marler B-)
 
It is stantard carridge return separated
 
Here is some code that you can you, but be warned . . . with a 1GB text file, this will not run real fast . . .



Code:
dim intFileHandle as integer
dim strLineData as string 
dim strFileName as string 
dim lngRowNumber as long

strFileName  = "c:MyFile.txt"


intFileHandle = FreeFile

open strFileName for intput as intFilehandle


lngRowNumber = 1
do while not eof(intFileHandle)

    Line Input #intFileHandle, strLineData

    if instr(1,strLineData,"Hello",vbTextCompare) > 0 then
        Debug.print "Row Number:=" & cstr(lngRowNumber)
    end if

    lngRowNumber = lngRowNumber +1

loop

close intFilehandle



This is VERY basic code and I imagine that you will probably want to add some functionality to it. Bascially, all it does it read in each line and search it for the string "Hello". If it finds it, then it will print the row number in the debug window. You will probably want to save that row number somewhere so that you app can use it.
Hope this helps you out! - Jeff Marler B-)
 
Great link HermanvLimbeek! But I don't think it will help here. See below . . .


From MS regarding FindText API . . .
"This article shows you how to use the FindText API function to programmatically enable searching in a Text box for the first match"


The file in question here is 1GB. This file is not one that I would want to load into memory let alone a textbox . . . it is far too big. the best way to scan this is to read it one line at a time. - Jeff Marler B-)
 
Yes Jeff,

you're right. I supposed the API was not limited to text boxes but it is. Since every other solution requires the individual rows to be read they will be slower. So your solution is probably the best.

Herman
 
HermanvLimbeek,
Don't get me wrong . . . I think that your link to the API information was great! It is an API that I will probably use for myself in the future. The problem here is the massive size of the file and the obvious lack of any concept of an index . . . The only real option I can think of on this is the brute force approach and just scan each line. - Jeff Marler B-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top