Does System.IO.StringReader does what you want? If not, you could use
an Encoding to get the bytes from the string, then
System.IO.MemoryStream to build a stream from those bytes.
I found this...
Stream stream = new
MemoryStream(System.Text.ASCIIEncoding.GetBytes(printbuffer));
but when I compile, it gives me this...
An object reference is required for the nonstatic field, method, or property
'System.Text.Encoding.GetBytes(string)'
You are missing the ASCII property form ASCIIEncoding:
System.Text.ASCIIEncoding.ASCII.GetBytes("test");
instead of:
System.Text.ASCIIEncoding.GetBytes(printbuffer)
BTW, I posted before an incorrect post, BitConverter.GetBytes() does not
have an overload for string , please ignore it.
You are missing the ASCII property form ASCIIEncoding:
System.Text.ASCIIEncoding.ASCII.GetBytes("test");
instead of:
System.Text.ASCIIEncoding.GetBytes(printbuffer)
BTW, I posted before an incorrect post, BitConverter.GetBytes() does not
have an overload for string , please ignore it.
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.ASCII;
- 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.)
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.