Solved

Memory Stream example in VB.NET 2003 !!

Posted on 2007-03-18
1
970 Views
Last Modified: 2013-12-17
Hi,

I want to write to memory a string "Hello World!" and i want to read it from memory using "Memory Stream" in Visual Basic.NET 2003. Can you please provide me the sample code for that ? Advance thanks for your time & patience.

Here is the sample code to write data:

Public Sub WriteToStream()

    Dim ms As New MemoryStream
    Dim strText As String = "Hello World!"
    Dim enc As New UTF8Encoding
    Dim arrBytData() As Byte = enc.GetBytes(strText)
    ms.Write(arrBytData, 0, arrBytData.Length)
    ms.Close()
    ms = Nothing

End Sub

Thanks
0
Comment
Question by:kishore_peddi
1 Comment
 
LVL 1

Accepted Solution

by:
xldev earned 500 total points
ID: 18743098
Is this what you are looking for?  This will read text from an existing memory stream.  One thing that you have to remember to do is to seek to the beginning of an existing stream before you read from it.

    Public Sub ReadFromStream(ByVal ms As MemoryStream)
        Dim data(ms.Length) As Byte
        Dim text As String

        ms.Seek(0, SeekOrigin.Begin)
        ms.Read(data, 0, data.Length)
        text = System.Text.Encoding.UTF8.GetString(data)
        ms.Close()

        MessageBox.Show(text)
    End Sub
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now