Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Read Byte Array into String for Delimiting?

Reply
 
Old 05-23-2008   #1 (permalink)
coconet


 
 

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.





My System SpecsSystem Spec
Old 05-23-2008   #2 (permalink)
Luc E. Mistiaen


 
 

Re: Read Byte Array into String for Delimiting?

Use Encoding.ASCII.GetString () on the byte [] or open a StreamReader or a
TextReader on your MemoryStream..

/LM

"coconet" <coconet@xxxxxx> wrote in message
news:1dce34dj47g7l3mhnksaiomromqafl8cd0@xxxxxx
Quote:

>
> 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.
>
>
>
>

My System SpecsSystem Spec
Old 05-23-2008   #3 (permalink)
coconet


 
 

Re: Read Byte Array into String for Delimiting?


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"
<luc.mistiaen@xxxxxx> wrote:
Quote:

>Use Encoding.ASCII.GetString () on the byte [] or open a StreamReader or a
>TextReader on your MemoryStream..
>
>/LM
>
>"coconet" <coconet@xxxxxx> wrote in message
>news:1dce34dj47g7l3mhnksaiomromqafl8cd0@xxxxxx
Quote:

>>
>> 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.
>>
>>
>>
>>
>
My System SpecsSystem Spec
Old 05-24-2008   #4 (permalink)
Jon Skeet [C# MVP]


 
 

Re: Read Byte Array into String for Delimiting?

coconet <coconet@xxxxxx> wrote:
Quote:

> 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 - <skeet@xxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Convert Byte() to string VB Script
Fast byte array comparison for ordering purposes .NET General
creating a byte array to read in image PowerShell
Creating a byte array PowerShell
String to Array PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46