Searching a file...

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
I need some guidance on the best way to proceed with searching a file content. I have a large file (see attachment) that is in text form, some of these files could be upto 50 times as big, therefore creating a huge file. These files contain information that is produced from another application and therefore I am unable to change the format of the file.

This file contains information that I want the user to be able to be able to enter search criteria in a form that then searches this file and returns information. The individual information is split into sections of data and this is defined by the section start label lbl{ and the end label }} Therefore the below information highlighted in bold is an individual section

lbl{-32768 21 12 0 text {Equip no: P-102B
Descr 1: RECYCLE PUMP-B
Descr 2:
}}

lbl{-32768 21 28 0 text {Equip no: D-100
Descr 1: COLUMN RECIEVER
Descr 2:
}}

Now comes the hard bit, in the bold section above you will notice that there is some text Equip no: P-102B I want the user to be able to enter in a form *102B* and for it to return -32768 21 12 0 which is after lbl{ and before text

Now obviously I could loop through the whole file to do this, however I am very concerned about RAM usage and also the time it will take to do this. Obviously the user could use this search option over and over again and therefore we would be searching the same file over and over again.

What I am wondering is if anyone has an idea on how best to do this?

One of my thoughts was to read the file once and output the content in an Access Database table and then use SQL to get the information? However would the user require Access on there machine to be able to do create the database or could I just ship a blank Access database with my app and then copy this and populate? Also I am not sure if Access is the best database, obviously I don't want people to have to use Oracle of SQL as this would require server configuration etc. but are there better free databases out there?

As you can see I just need a bit of guidance on how to achieve this, your help would really be appreshiated

Thanks

Simon
 

Attachments

  • EAP1102.txt
    45.2 KB · Views: 23
Hello.

You could read the file in once into a huge string (ReadAllLines() or what it was called), split it by "lbl{", loop through this new array and put the information into a list or array of structures.
After that, you can easily loop through all this array, looking for some condition and returning the needed values.

Memory usage is a good point somewhere if you're reading a 2MB file...but though, I wouldn't worry about it and just try it out as long as the machines do have more then 256MB RAM.

Bobby
 
How about: Read the file, parse the two fields you want with Regex and then store both of the items in a HashTable, then when you get a match with the <key> - user entered a valid item then return the value paired with it.
 
Back
Top