PC Review


Reply
Thread Tools Rate Thread

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

 
 
=?Utf-8?B?QmVhbkRvZw==?=
Guest
Posts: n/a
 
      5th Sep 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?

Thanks!



~BenDilts( void );

 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      5th Sep 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.
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      5th Sep 2005
BeanDog <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
string to a stream prefersgolfing Microsoft VB .NET 5 17th Nov 2005 05:24 PM
String stream in .NET??? =?Utf-8?B?VFQgKFRvbSBUZW1wZWxhZXJlKQ==?= Microsoft C# .NET 4 3rd Mar 2005 03:19 PM
Stream into String Chad Z. Hower aka Kudzu Microsoft Dot NET 7 18th Feb 2004 06:04 PM
String to Stream Hayato Iriumi Microsoft VB .NET 6 10th Oct 2003 12:18 PM
String to stream Al Microsoft Dot NET 3 13th Sep 2003 12:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:01 PM.