How to: Convert an Array of Bytes into a String in Visual BasicĀ
This topic shows how to convert the bytes from a byte array into a string.
Example
This example uses the GetString method of the System.Text.Encoding.Unicode encoding class to convert all the bytes from a byte array into a string.
Private Function UnicodeBytesToString( _
ByVal bytes() As Byte) _
As String
Return System.Text.Encoding.Unicode.GetString(bytes)
End Function
You can choose from several encoding options to convert a byte array into a string:
System.Text.Encoding.ASCII: Gets an encoding for the ASCII (7-bit) character set.
System.Text.Encoding.BigEndianUnicode: Gets an encoding for the UTF-16 format using the big-endian byte order.
System.Text.Encoding.Default: Gets an encoding for the system's current ANSI code page.
System.Text.Encoding.Unicode: Gets an encoding for the UTF-16 format using the little-endian byte order.
System.Text.Encoding.UTF32: Gets an encoding for the UTF-32 format using the little-endian byte order.
System.Text.Encoding.UTF7: Gets an encoding for the UTF-7 format.
System.Text.Encoding.UTF8: Gets an encoding for the UTF-8 format.
See Also
Tasks
How to: Convert Strings into an Array of Bytes in Visual Basic