Solved

Memory Stream example in VB.NET 2003 !!

Posted on 2007-03-18
1
984 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

16 Experts available now in Live!

Get 1:1 Help Now