Byte Array To String

Here is a very simple code snippet for converting a Byte Array to a String in VB.Net

Encoding.ASCII.GetString(bytes)

And here is a function for that uses it to convert a byte array to a string

    
Private Function streamToString(ByVal stream As System.IO.MemoryStream) As String
Dim o As New IO.StreamWriter(stream, System.Text.Encoding.Default)
Dim bytes(stream.Length - 1) As Byte
stream.Read(bytes, 0, stream.Length - 1)
Return Encoding.ASCII.GetString(bytes)
End Function

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s