Solved

Memory Stream example in VB.NET 2003 !!

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Convert Silverlight ERP To Angularjs,HTML5 3 62
Visual Studio npm 1 29
What is newest platform to convert a massive Windows Forms program to? 7 52
SSIS GUID Variable 2 37
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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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