logo       

RE: Converting a MemoryStream to a String: msg#00072

Subject: RE: Converting a MemoryStream to a String
I haven?t actually tried this, but the first thing that comes to mind is to
do something fairly ugly along the line of reading the MemoryStream into a
byte array and then using an appropriate Encoding class (e.g. UTF8Encoding)
to get the characters from the byte array using the GetChars method?

 

I?m not sure this is the appropriate way of doing depending on your scenario
(performance, memory usage, etc), but it should at least get you started.

 

Of course, you could also do something like reading from the MemoryStream
and appending each byte or byte pair (depending on the encoding) to a
StringBuilder (optionally using an Encoding object on the byte/byte-pair
first).

 

If you just want the raw data (i.e. doing a hex-string representation of the
stream contents), you can just append byte after byte to a StringBuilder.

 

/Mats

 

From: padnug@xxxxxxxxxxxxxxx [mailto:padnug@xxxxxxxxxxxxxxx] On Behalf Of
Keith R. Pinster
Sent: Wednesday, June 14, 2006 11:49 AM
To: padnug@xxxxxxxxxxxxxxx
Subject: [padnug] Converting a MemoryStream to a String

 

I've been banging my head against this for a couple of hours and just 
can't figure it out. I've got an object that dumps it's result into a 
MemoryStream object. Can someone tell me how to convert this to a 
string?

Thanks
KRP

 



[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get to your groups with one click. Know instantly when new email arrives
http://us.click.yahoo.com/.7bhrC/MGxNAA/yQLSAA/dpFolB/TM
--------------------------------------------------------------------~-> 

 


<Prev in Thread] Current Thread [Next in Thread>