Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Memory Stream example in VB.NET 2003 !!

Posted on 2007-03-18
1
Medium Priority
?
1,005 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
[X]
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
1 Comment
 
LVL 1

Accepted Solution

by:
xldev earned 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

722 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