Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Memory Stream example in VB.NET 2003 !!

Posted on 2007-03-18
1
988 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…

791 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