[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Fast MemoryStream to String Conversion?

Danny

10/15/2003 3:30:00 AM

Hi.

What is the fastest way to convert a memory stream (containing a byte []) to
a string?

Thanks.

-Danny-


7 Answers

Ali Mazaheri,MCAD

10/15/2003 5:59:00 AM

0

bitconverter.tostring(memorystream.toarray)

"Danny" <industrial_disease@hotmail.com> wrote in message
news:eQ33kyskDHA.2328@TK2MSFTNGP10.phx.gbl...
> Hi.
>
> What is the fastest way to convert a memory stream (containing a byte [])
to
> a string?
>
> Thanks.
>
> -Danny-
>
>


Danny

10/15/2003 8:43:00 PM

0

Thanks Ali.

BitConverter returns a string with hexadecimal pairs (that correspond to
each byte in the array). How do I get a regular string? I am trying to
serialize XML into a string and I want to avoid writing the XML to a file
first. I am using a MemoryStream (I need to use a MemoryStream via
XmlTextWriter in order to change the default encoding) and calling Serialize
(off XmlSerializer) to that stream. I then want to get a string from the
stream return it to the caller.

Thanks!

-Danny-

"Ali Mazaheri,MCAD" <mcad@vb.net> wrote in message
news:epqTBFukDHA.3612@TK2MSFTNGP11.phx.gbl...
> bitconverter.tostring(memorystream.toarray)
>
> "Danny" <industrial_disease@hotmail.com> wrote in message
> news:eQ33kyskDHA.2328@TK2MSFTNGP10.phx.gbl...
> > Hi.
> >
> > What is the fastest way to convert a memory stream (containing a byte
[])
> to
> > a string?
> >
> > Thanks.
> >
> > -Danny-
> >
> >
>
>


Girish Bharadwaj

10/15/2003 8:53:00 PM

0

ASCIIEncoding.GetString().. might be able to help you out.

Danny wrote:
> Thanks Ali.
>
> BitConverter returns a string with hexadecimal pairs (that correspond to
> each byte in the array). How do I get a regular string? I am trying to
> serialize XML into a string and I want to avoid writing the XML to a file
> first. I am using a MemoryStream (I need to use a MemoryStream via
> XmlTextWriter in order to change the default encoding) and calling Serialize
> (off XmlSerializer) to that stream. I then want to get a string from the
> stream return it to the caller.
>
> Thanks!
>
> -Danny-
>
> "Ali Mazaheri,MCAD" <mcad@vb.net> wrote in message
> news:epqTBFukDHA.3612@TK2MSFTNGP11.phx.gbl...
>
>>bitconverter.tostring(memorystream.toarray)
>>
>>"Danny" <industrial_disease@hotmail.com> wrote in message
>>news:eQ33kyskDHA.2328@TK2MSFTNGP10.phx.gbl...
>>
>>>Hi.
>>>
>>>What is the fastest way to convert a memory stream (containing a byte
>
> [])
>
>>to
>>
>>>a string?
>>>
>>>Thanks.
>>>
>>>-Danny-
>>>
>>>
>>
>>
>
>


--
Girish Bharadwaj

Ali Mazaheri,MCAD

10/15/2003 10:28:00 PM

0

As Girish Mentioned you can leverage system.encoding classes for that
purpose.

"Girish Bharadwaj" <girishb@nowhere> wrote in message
news:3F8DB3BA.50106@nowhere...
> ASCIIEncoding.GetString().. might be able to help you out.
>
> Danny wrote:
> > Thanks Ali.
> >
> > BitConverter returns a string with hexadecimal pairs (that correspond to
> > each byte in the array). How do I get a regular string? I am trying to
> > serialize XML into a string and I want to avoid writing the XML to a
file
> > first. I am using a MemoryStream (I need to use a MemoryStream via
> > XmlTextWriter in order to change the default encoding) and calling
Serialize
> > (off XmlSerializer) to that stream. I then want to get a string from the
> > stream return it to the caller.
> >
> > Thanks!
> >
> > -Danny-
> >
> > "Ali Mazaheri,MCAD" <mcad@vb.net> wrote in message
> > news:epqTBFukDHA.3612@TK2MSFTNGP11.phx.gbl...
> >
> >>bitconverter.tostring(memorystream.toarray)
> >>
> >>"Danny" <industrial_disease@hotmail.com> wrote in message
> >>news:eQ33kyskDHA.2328@TK2MSFTNGP10.phx.gbl...
> >>
> >>>Hi.
> >>>
> >>>What is the fastest way to convert a memory stream (containing a byte
> >
> > [])
> >
> >>to
> >>
> >>>a string?
> >>>
> >>>Thanks.
> >>>
> >>>-Danny-
> >>>
> >>>
> >>
> >>
> >
> >
>
>
> --
> Girish Bharadwaj
>


Danny

10/15/2003 10:56:00 PM

0

ASCIIEncoding.GetString() worked.

Thanks Ali & Girish!

Cheers.

-Danny-

"Ali Mazaheri, MCAD" <mcad@vb.net> wrote in message
news:OPV9zt2kDHA.2364@TK2MSFTNGP11.phx.gbl...
> As Girish Mentioned you can leverage system.encoding classes for that
> purpose.
>
> "Girish Bharadwaj" <girishb@nowhere> wrote in message
> news:3F8DB3BA.50106@nowhere...
> > ASCIIEncoding.GetString().. might be able to help you out.
> >
> > Danny wrote:
> > > Thanks Ali.
> > >
> > > BitConverter returns a string with hexadecimal pairs (that correspond
to
> > > each byte in the array). How do I get a regular string? I am trying to
> > > serialize XML into a string and I want to avoid writing the XML to a
> file
> > > first. I am using a MemoryStream (I need to use a MemoryStream via
> > > XmlTextWriter in order to change the default encoding) and calling
> Serialize
> > > (off XmlSerializer) to that stream. I then want to get a string from
the
> > > stream return it to the caller.
> > >
> > > Thanks!
> > >
> > > -Danny-
> > >
> > > "Ali Mazaheri,MCAD" <mcad@vb.net> wrote in message
> > > news:epqTBFukDHA.3612@TK2MSFTNGP11.phx.gbl...
> > >
> > >>bitconverter.tostring(memorystream.toarray)
> > >>
> > >>"Danny" <industrial_disease@hotmail.com> wrote in message
> > >>news:eQ33kyskDHA.2328@TK2MSFTNGP10.phx.gbl...
> > >>
> > >>>Hi.
> > >>>
> > >>>What is the fastest way to convert a memory stream (containing a byte
> > >
> > > [])
> > >
> > >>to
> > >>
> > >>>a string?
> > >>>
> > >>>Thanks.
> > >>>
> > >>>-Danny-
> > >>>
> > >>>
> > >>
> > >>
> > >
> > >
> >
> >
> > --
> > Girish Bharadwaj
> >
>
>


Michael Giagnocavo

10/16/2003 12:13:00 AM

0

Just make sure it's ASCII!! Safer would be UTF8.
-mike
MVP

"Danny" <industrial_disease@hotmail.com> wrote in message
news:eHnwD%232kDHA.1096@TK2MSFTNGP11.phx.gbl...
> ASCIIEncoding.GetString() worked.
>
> Thanks Ali & Girish!
>
> Cheers.
>
> -Danny-
>
> "Ali Mazaheri, MCAD" <mcad@vb.net> wrote in message
> news:OPV9zt2kDHA.2364@TK2MSFTNGP11.phx.gbl...
> > As Girish Mentioned you can leverage system.encoding classes for that
> > purpose.
> >
> > "Girish Bharadwaj" <girishb@nowhere> wrote in message
> > news:3F8DB3BA.50106@nowhere...
> > > ASCIIEncoding.GetString().. might be able to help you out.
> > >
> > > Danny wrote:
> > > > Thanks Ali.
> > > >
> > > > BitConverter returns a string with hexadecimal pairs (that
correspond
> to
> > > > each byte in the array). How do I get a regular string? I am trying
to
> > > > serialize XML into a string and I want to avoid writing the XML to a
> > file
> > > > first. I am using a MemoryStream (I need to use a MemoryStream via
> > > > XmlTextWriter in order to change the default encoding) and calling
> > Serialize
> > > > (off XmlSerializer) to that stream. I then want to get a string from
> the
> > > > stream return it to the caller.
> > > >
> > > > Thanks!
> > > >
> > > > -Danny-
> > > >
> > > > "Ali Mazaheri,MCAD" <mcad@vb.net> wrote in message
> > > > news:epqTBFukDHA.3612@TK2MSFTNGP11.phx.gbl...
> > > >
> > > >>bitconverter.tostring(memorystream.toarray)
> > > >>
> > > >>"Danny" <industrial_disease@hotmail.com> wrote in message
> > > >>news:eQ33kyskDHA.2328@TK2MSFTNGP10.phx.gbl...
> > > >>
> > > >>>Hi.
> > > >>>
> > > >>>What is the fastest way to convert a memory stream (containing a
byte
> > > >
> > > > [])
> > > >
> > > >>to
> > > >>
> > > >>>a string?
> > > >>>
> > > >>>Thanks.
> > > >>>
> > > >>>-Danny-
> > > >>>
> > > >>>
> > > >>
> > > >>
> > > >
> > > >
> > >
> > >
> > > --
> > > Girish Bharadwaj
> > >
> >
> >
>
>


Danny

10/16/2003 1:22:00 AM

0

Thanks Mike! UTF8 also worked and I'll use this to be safe.

Cheers.

-Danny-

"Michael Giagnocavo [MVP]" <mggUNSPAM@Atrevido.net> wrote in message
news:#sbYnp3kDHA.1708@TK2MSFTNGP12.phx.gbl...
> Just make sure it's ASCII!! Safer would be UTF8.
> -mike
> MVP
>
> "Danny" <industrial_disease@hotmail.com> wrote in message
> news:eHnwD%232kDHA.1096@TK2MSFTNGP11.phx.gbl...
> > ASCIIEncoding.GetString() worked.
> >
> > Thanks Ali & Girish!
> >
> > Cheers.
> >
> > -Danny-
> >
> > "Ali Mazaheri, MCAD" <mcad@vb.net> wrote in message
> > news:OPV9zt2kDHA.2364@TK2MSFTNGP11.phx.gbl...
> > > As Girish Mentioned you can leverage system.encoding classes for that
> > > purpose.
> > >
> > > "Girish Bharadwaj" <girishb@nowhere> wrote in message
> > > news:3F8DB3BA.50106@nowhere...
> > > > ASCIIEncoding.GetString().. might be able to help you out.
> > > >
> > > > Danny wrote:
> > > > > Thanks Ali.
> > > > >
> > > > > BitConverter returns a string with hexadecimal pairs (that
> correspond
> > to
> > > > > each byte in the array). How do I get a regular string? I am
trying
> to
> > > > > serialize XML into a string and I want to avoid writing the XML to
a
> > > file
> > > > > first. I am using a MemoryStream (I need to use a MemoryStream via
> > > > > XmlTextWriter in order to change the default encoding) and calling
> > > Serialize
> > > > > (off XmlSerializer) to that stream. I then want to get a string
from
> > the
> > > > > stream return it to the caller.
> > > > >
> > > > > Thanks!
> > > > >
> > > > > -Danny-
> > > > >
> > > > > "Ali Mazaheri,MCAD" <mcad@vb.net> wrote in message
> > > > > news:epqTBFukDHA.3612@TK2MSFTNGP11.phx.gbl...
> > > > >
> > > > >>bitconverter.tostring(memorystream.toarray)
> > > > >>
> > > > >>"Danny" <industrial_disease@hotmail.com> wrote in message
> > > > >>news:eQ33kyskDHA.2328@TK2MSFTNGP10.phx.gbl...
> > > > >>
> > > > >>>Hi.
> > > > >>>
> > > > >>>What is the fastest way to convert a memory stream (containing a
> byte
> > > > >
> > > > > [])
> > > > >
> > > > >>to
> > > > >>
> > > > >>>a string?
> > > > >>>
> > > > >>>Thanks.
> > > > >>>
> > > > >>>-Danny-
> > > > >>>
> > > > >>>
> > > > >>
> > > > >>
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Girish Bharadwaj
> > > >
> > >
> > >
> >
> >
>
>