String stream in VB.NET 2003 (.NET 1.1)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some libraries that will write to a stream. I would like them to write
to a string, which I can then manipulate in memory, rather than to a file. I
cannot find documentation for how to get a stream that writes to or reads
from a string.

Is such functionality available?

Thanks!



~BenDilts( void );
 
I have some libraries that will write to a stream. I would like them to write
to a string, which I can then manipulate in memory, rather than to a file. I
cannot find documentation for how to get a stream that writes to or reads
from a string.

Is such functionality available?

You can't write to strings since they are immutable.

If you need a stream you can use a MemoryStream, and then convert the
content to/from a string. Or you can write your own Stream class
wrapping a StringBuilder.

If a TextWriter will work, use the StringWriter class.


Mattias
 
BeanDog said:
I have some libraries that will write to a stream. I would like them to write
to a string, which I can then manipulate in memory, rather than to a file. I
cannot find documentation for how to get a stream that writes to or reads
from a string.

Is such functionality available?

Thanks!

Streams contain binary data - strings are text data. You can use a
MemoryStream to keep the data in memory, and then if you *know* that
the contents are a string encoded in a certain way, you could convert
the data to a string later. You shouldn't use a string as a way of
storing binary data though - byte arrays should be used for that
purpose.
 
Back
Top