How to read a fixed row from text file?


julius228

Recommended Posts

What is the best way to read a certain row from a txt file?

Let's say I want read row number 750 from a txt file that contain 1000 row and I dont want scroll all the file.

There is a straight way to do it?

Any suggestion is appreciated.

Many thanks in advantage.

Giulio

Link to comment
Share on other sites

Unless the rows are all the same length, there is no way to do it other than to read the whole file. This is true in any language as the operating system really can only randomly seek based on a byte position in the file which you can't really calculate. You could keep a table of those positions, but truthfully, I'd just use the file.readDelim() function to quickly read all the rows up to and including the one I want and then toss the rest (or cache it if you want to be real advanced). readDelim() is much faster than creating a loop in DAQFactory and doing file.read(). If you want the whole line, just pass an obscure character, like chr(255) as the parse by parameter.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.