read text file display data by chunk

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text file that has a length of 840 bytes. I need to split into 20
bytes starting from byte 1. If there are data in any of the 20 bytes, I
display the data. So there are 42 occurences of 20 bytes. How do I read each
of the 20 bytes and display the data in C#?
 
Tim2Be,

I assume that records are not delimited by end of line characters, etc.,
in which case, you would want to use a System.IO.FileStream and read
20 bytes at a time using its Read() method. You'll read into a byte[]
and if necessary convert it to a string or whatever you need.

If you are dealing with a text file then in the simplest case, use
File.OpenText() to get a StreamReader and call the ReadLine() method.

That should get you pointed in the right direction.

--Bob
 
Let say that I have a test string of with a lenght of 840 characters, can I
use a FileStream? I need to read each each of the 20 characters to see if
there is any data in each of the 20 characters. If there is than I display
the data. I don't think the FileStream will work? Can someone provide an
example?

Bob Grommes said:
Tim2Be,

I assume that records are not delimited by end of line characters, etc.,
in which case, you would want to use a System.IO.FileStream and read
20 bytes at a time using its Read() method. You'll read into a byte[]
and if necessary convert it to a string or whatever you need.

If you are dealing with a text file then in the simplest case, use
File.OpenText() to get a StreamReader and call the ReadLine() method.

That should get you pointed in the right direction.

--Bob
I have a text file that has a length of 840 bytes. I need to split into 20
bytes starting from byte 1. If there are data in any of the 20 bytes, I
display the data. So there are 42 occurences of 20 bytes. How do I read each
of the 20 bytes and display the data in C#?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top