I found this...
Stream stream = new
MemoryStream(Sy stem.Text.ASCII Encoding.GetByt es(printbuffer) );
but when I compile, it gives me this...
An object reference is required for the nonstatic field, method, or property
'System.Text.En coding.GetBytes (string)'
What does this mean?
Thanks for any help...
"Randy" <temp@temp.co m> wrote in message
news:u4HSbsBjDH A.1544@tk2msftn gp13.phx.gbl...[color=blue]
> Hello,
> Is there an easy way to convert a string to a stream?
> Thanks
>
>[/color]
Randy <temp@temp.co m> wrote:[color=blue]
> Is there an easy way to convert a string to a stream?[/color]
Does System.IO.Strin gReader does what you want? If not, you could use
an Encoding to get the bytes from the string, then
System.IO.Memor yStream to build a stream from those bytes.
MemoryStream mstream = new MemoryStream( BitConverter.Ge tBytes(
string_var) );
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Randy" <temp@temp.co m> wrote in message
news:u4HSbsBjDH A.1544@tk2msftn gp13.phx.gbl...[color=blue]
> Hello,
> Is there an easy way to convert a string to a stream?
> Thanks
>
>[/color]
StringReader seems to work great! Thanks for your help...
"Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
news:MPG.19eb96 064051340a9897f 1@msnews.micros oft.com...[color=blue]
> Randy <temp@temp.co m> wrote:[color=green]
> > Is there an easy way to convert a string to a stream?[/color]
>
> Does System.IO.Strin gReader does what you want? If not, you could use
> an Encoding to get the bytes from the string, then
> System.IO.Memor yStream to build a stream from those bytes.
>
> --
> Jon Skeet - <skeet@pobox.co m>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too[/color]
You are missing the ASCII property form ASCIIEncoding:
System.Text.ASC IIEncoding.ASCI I.GetBytes("tes t");
instead of:
System.Text.ASC IIEncoding.GetB ytes(printbuffe r)
BTW, I posted before an incorrect post, BitConverter.Ge tBytes() does not
have an overload for string , please ignore it.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Randy" <temp@temp.co m> wrote in message
news:eAiM0vBjDH A.3192@TK2MSFTN GP11.phx.gbl...[color=blue]
> I found this...
> Stream stream = new
> MemoryStream(Sy stem.Text.ASCII Encoding.GetByt es(printbuffer) );
> but when I compile, it gives me this...
> An object reference is required for the nonstatic field, method, or[/color]
property[color=blue]
> 'System.Text.En coding.GetBytes (string)'
>
> What does this mean?
> Thanks for any help...
>
> "Randy" <temp@temp.co m> wrote in message
> news:u4HSbsBjDH A.1544@tk2msftn gp13.phx.gbl...[color=green]
> > Hello,
> > Is there an easy way to convert a string to a stream?
> > Thanks
> >
> >[/color]
>
>[/color]
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:u48Ay6BjDH A.1072@TK2MSFTN GP09.phx.gbl...[color=blue]
>
>
> Hi Randy,
>
> You are missing the ASCII property form ASCIIEncoding:
> System.Text.ASC IIEncoding.ASCI I.GetBytes("tes t");
> instead of:
> System.Text.ASC IIEncoding.GetB ytes(printbuffe r)
>
>
> BTW, I posted before an incorrect post, BitConverter.Ge tBytes() does not
> have an overload for string , please ignore it.
>
> Cheers,
>
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
> "Randy" <temp@temp.co m> wrote in message
> news:eAiM0vBjDH A.3192@TK2MSFTN GP11.phx.gbl...[color=green]
> > I found this...
> > Stream stream = new
> > MemoryStream(Sy stem.Text.ASCII Encoding.GetByt es(printbuffer) );
> > but when I compile, it gives me this...
> > An object reference is required for the nonstatic field, method, or[/color]
> property[color=green]
> > 'System.Text.En coding.GetBytes (string)'
> >
> > What does this mean?
> > Thanks for any help...
> >
> > "Randy" <temp@temp.co m> wrote in message
> > news:u4HSbsBjDH A.1544@tk2msftn gp13.phx.gbl...[color=darkred]
> > > Hello,
> > > Is there an easy way to convert a string to a stream?
> > > Thanks
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.mach in AT
dot.state.fl.us >> wrote:[color=blue]
> You are missing the ASCII property form ASCIIEncoding:[/color]
Note that it's actually a property of Encoding, not ASCIIEncoding -
it's just visible through ASCIIEncoding as well, of course. I
personally prefer to read:
Encoding ascii = Encoding.ASCII;
rather than
Encoding ascii = ASCIIEncoding.A SCII;
- the latter gives the impression that the property is a member of the
ASCIIEncoding class.
(Obviously the same goes for the other built-in encodings.)
Comment