Read Text From Stream Then Reposition And Repeat

  • Thread starter Thread starter Garibaldi
  • Start date Start date
G

Garibaldi

Thanks to all...

I need to read a block of text, operate on the read text then move to the
next text block and so on and so on from a 650MB file.

Pseudo code would be something like this:

1. Start at the beginning of the text file
2. Read in 100K of text
3. Work with the 100K of text
4. Repostion the cursor to the start of the next text block (position now
100001)
5. Read in 100K of text
6. Work with the 100K of text
7. Repostion the cursor to the start of the next text block (position now
200001)
8. Read in 100K of text
9. etc

I'm thinking that I need to use the StreamReader.Read function. Is this the
best approach? What approach will be the fastest?

Thanks very much

-- ty_92648 AT hotmail.com
 
Thanks to all...

I need to read a block of text, operate on the read text then move to the
next text block and so on and so on from a 650MB file.

Pseudo code would be something like this:

1. Start at the beginning of the text file
2. Read in 100K of text
3. Work with the 100K of text
4. Repostion the cursor to the start of the next text block (position now
100001)
5. Read in 100K of text
6. Work with the 100K of text
7. Repostion the cursor to the start of the next text block (position now
200001)
8. Read in 100K of text
9. etc

I'm thinking that I need to use the StreamReader.Read function. Is this the
best approach? What approach will be the fastest?

Why bother repositioning? Just read in the first 100K, then read in the
next 100K with the same StreamReader, etc.
 
Hi,

If you are reading text the best way of doing it is using StreamReader
class
Now depending of what you are doing you can use two approachs
1- treat the reading as lines using ReadLine() and keeping them in a
string[]
2- treat the text as a group of char and reading then on a char[] as you
proposed. if you dont need to keep track of lines this is the best way

Btw, you don;t need to reposition the stream, unless that you need to write
back the modified data (which is entirely another matter ).

Cheers,
 
Back
Top