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 );

Re: String stream in VB.NET 2003 (.NET 1.1) by Mattias

Mattias
Mon Sep 05 12:12:18 CDT 2005


>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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Re: String stream in VB.NET 2003 (.NET 1.1) by Jon

Jon
Mon Sep 05 13:59:17 CDT 2005

BeanDog <BeanDog@discussions.microsoft.com> wrote:
> 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.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too