Results 1 to 2 of 2

Thread: How to modify text in memory stream?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    How to modify text in memory stream?

    I'm writing some text to a memory stream and need to modify it once in the memory stream. The reason I can't modify prior to adding to the memory stream is that it is from some 3rd party component. Here is an example:

    ms = New MemoryStream
    doc.Save(ms, SaveFormat.Html)

    I need to do some modification to the resulting text that ends up in ms. Is there a way to convert the contents of ms into a string, and then back into a memory stream once modified?

    Visual Studio 2010

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How to modify text in memory stream?

    You already know how because you've probably done it many times before: a StreamReader. A StreamReader reads text from a Stream. It's usually a FileStream because the text usually comes from a file, but it can be any type of Stream you want. Likewise a StreamWriter can write text to any Stream. Just make sure that you set the Position to the beginning of the Stream before reading or writing.

    Also, I'm not 100% sure what happens if you write less data than is already in the Stream. Maybe the overflow gets truncated and maybe it doesn't, so you should do some testing to see for your self.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width