473,320 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

read text file display data by chunk

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#?
Sep 18 '06 #1
2 5237
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

Tim2Be wrote:
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#?
Sep 19 '06 #2
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" wrote:
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

Tim2Be wrote:
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#?
Sep 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Chris | last post by:
Can anybody help. I need to read a txt file backwords line by line. Can anybody help me do this. Thanks Chris
75
by: Greg McIntyre | last post by:
I have a Python snippet: f = open("blah.txt", "r") while True: c = f.read(1) if c == '': break # EOF # ... work on c Is some way to make this code more compact and simple? It's a bit...
3
by: Krish | last post by:
I have requirement, that i get one big chunk of text file. This text file will have has information, that on finding "****End of Information****", i have to split them individual text file with our...
8
by: kepioo | last post by:
I currently have an xml input file containing lots of data. My objectiv is to write a script that reports in another xml file only the data I am interested in. Doing this is really easy using SAX....
12
by: Sean Davis | last post by:
I am working on a simple script to read from one database (oracle) and write to another (postgresql). I retrieve the data from oracle in chunks and drop the data to postgresql continuously. The...
6
by: ericunfuk | last post by:
Hi ALL, I want to read a binary file(it's pic.tif file, I guess it's binary file?), then write it to a new file), I have several questions about this process: When I use fread() to read a...
0
by: Killer42 | last post by:
Here is a very simple example routine which reads a file from disk, in one big lump. This uses the built-in VB statements only. Later we will cover the FileSystemObject, which provides greater...
2
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it...
5
by: brad | last post by:
How would I determine the number of bytes that is.read actually read? // allocate memory char * buffer; while (!is.eof()) { buffer = new char ;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.