What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 30842 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > C# > How to convert Stream into String? ...
Poster

How to convert Stream into String?

 Code Snippet posted by: Poster | Posted on: 6/13/2009 | Category: C# Codes | Views: 19385 | Status: [Member] | Alert Moderator   


To convert Stream object into String, write following code in C#.

        Stream stream = GetStream();

byte[] bytes = new byte[stream.Length];
stream.Position = 0;
stream.Read(bytes, 0, (int)stream.Length);
string data = Encoding.ASCII.GetString(bytes); // this is your string


In VB.NET, write following code.

Dim tream As Stream = GetStream()

Dim bytes As Byte() = New Byte(tream.Length) {}
tream.Position = 0
tream.Read(bytes, 0, DirectCast(tream.Length, Integer))
Dim data As String = Encoding.ASCII.GetString(bytes) ' this is your string


You need to use System.IO and System.Text namespace to work with above code.
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 8:28:28 AM