Reading Text files
Posted on 2008-06-19
Im writing a program which reads information from numerous text files and currently I am reading all the information from the text file into an array of structs then manupilating my data from there.
I am programming an option that will allow the user to see a machine history over several months due to this I need to open and read alot of text files. As there is alot of information I dont think the way im doing it is the best solution.
SUB-BATCH,C1.0 M2.1,16-01-08,001020005013,A: ,B: 1,C:2,D: ,ID:12,0,0,0,0,0,0,5000,0,CT:,5000,0,0,0,0,RT:,0,GT:,5000,
Shown above is an example of a record stored in my text file. Normally I would search each file based on b and c number that the user enters. In the example above not only would I be searching for b and c number but also for type = SUB-BATCH. All my fields are seperated by a comma and at the end of each record is a newline character.
What I would like to know is there anyway I can go through a text file searching for the b and c number (and type in this case) find a match and only extract that record from the file without having to read the whole file.
Few more points - some of my text files have numerous records with the same b and c number others have only one record per machine but based on the text file I always know what position in the text file that the b and c number will occur.
Any help greatly appreciated