Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Codes Author
Sun, 31-Aug-2014 Authors
All Time Authors
Satyapriyanayak
12160
Jayakumars
8120
Niladri.biswas
6000

Latest members | More ...


(Statistics delayed by 5 minutes)
 Codes

How to convert Stream into String?

Poster
Posted by Poster under C# on 6/13/2009 8:33:30 AM | Views : 41198 | Status : [Member]

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:



Comments or Responses


Login to post response