473,378 Members | 1,495 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,378 software developers and data experts.

Read Byte Array into String for Delimiting?


I have a byte[] that came from a network resource. I would like to
read this "line by line" and split it on tab character. The bytes are
ASCII encoded, so there should be real EOL markers. I have my
MemoryStream on the bytes, now how can I quickly read it?

I can't use LINQ because I am working strictly with an instance Type.

Thanks. .NET 3.5.


Jun 27 '08 #1
3 1356
Use Encoding.ASCII.GetString () on the byte [] or open a StreamReader or a
TextReader on your MemoryStream..

/LM

"coconet" <co*****@community.nospamwrote in message
news:1d********************************@4ax.com...
>
I have a byte[] that came from a network resource. I would like to
read this "line by line" and split it on tab character. The bytes are
ASCII encoded, so there should be real EOL markers. I have my
MemoryStream on the bytes, now how can I quickly read it?

I can't use LINQ because I am working strictly with an instance Type.

Thanks. .NET 3.5.


Jun 27 '08 #2

The initial byte[] is huge, so I'd rather not turn it into a single
giant string with GetString(). I think what I want to do is read the
byte[] until I hit Environment.NewLine, then re-read the byte[] into a
tempbyte[] with an offset from n to n+read. Then I can to GetString()
on that piece. But I don't know how to code that. I want to use Read
or ReadBytes, maybe BeginRead() to make it Async so I can report what
I'm working on. But I don't know how the code could look.

Help with any guidance code?

Thanks.

On Sat, 24 May 2008 05:03:08 +0200, "Luc E. Mistiaen"
<lu**********@advalvas.be.no.spamwrote:
>Use Encoding.ASCII.GetString () on the byte [] or open a StreamReader or a
TextReader on your MemoryStream..

/LM

"coconet" <co*****@community.nospamwrote in message
news:1d********************************@4ax.com.. .
>>
I have a byte[] that came from a network resource. I would like to
read this "line by line" and split it on tab character. The bytes are
ASCII encoded, so there should be real EOL markers. I have my
MemoryStream on the bytes, now how can I quickly read it?

I can't use LINQ because I am working strictly with an instance Type.

Thanks. .NET 3.5.

Jun 27 '08 #3
coconet <co*****@community.nospamwrote:
The initial byte[] is huge, so I'd rather not turn it into a single
giant string with GetString(). I think what I want to do is read the
byte[] until I hit Environment.NewLine, then re-read the byte[] into a
tempbyte[] with an offset from n to n+read. Then I can to GetString()
on that piece. But I don't know how to code that. I want to use Read
or ReadBytes, maybe BeginRead() to make it Async so I can report what
I'm working on. But I don't know how the code could look.
Use StreamReader and ReadLine - that will only read one line at a time
(plus a bit for buffering).

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Jun 27 '08 #4

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

Similar topics

1
by: Brian | last post by:
I'm having intermittent trouble with a call to the Read method of the HttpWebResponse object. I get an ArumentOutOfRangeException claiming that deep down inside of the Read method, the count...
8
by: collinm | last post by:
hi we use linux and c language under bash i do echo -e \\000\\000\\000\\000\000\\001Z00\\002AA LINUX \\004 >/dev/ttyS2 that send command to a led display (alpha sign communication)
0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
5
by: AC [MVP MCMS] | last post by:
Any pointers on how to (1) read a Base64 encoded string from a text file and (2) write it to a binary file? I have a ton of files that are being generated from a legacy system. Each file...
10
by: Tibby | last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file. -- Thanks --- Outgoing mail is certified Virus...
0
by: lovecarole | last post by:
hi, i am the student who should write a program about reading wav file and do the DFT. actually i don't know how to read data of the wav song and save it into the array... if i want to read...
4
by: parez | last post by:
Hi, When does the socket (server) know when to stop reading. e.g. if i have a buffer = 25K and do networkStream.write twice.. what will the server read? 25k or 50K?
5
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a...
3
by: sam | last post by:
same as subject?
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.