I have the following piece of code to convert a Byte Array to a String,
but there is something going wrong with the encoding !!
After running the text (or text1 or text2 or text3 or even text4 string) is completly empty . What the am i missing here ??? Am i right that it has to do something with the encoding ? If so, what am I doing wrong ?
Thanks
Mjcm
but there is something going wrong with the encoding !!
VB.NET:
Sub Main()
Dim fs As FileStream
' file.bin is a binary file !
fs = New FileStream("d:\file.bin", FileMode.Open, FileAccess.Read)
Dim bytes(fs.Length) As Byte
Console.WriteLine(ConvertByteArrayToString(bytes))
End Sub
Private Function ConvertByteArrayToString(ByVal byteArray As Byte()) As String
Dim enc As Encoding = Encoding.ASCII
Dim enc1 As Encoding = Encoding.UTF7
Dim enc2 As Encoding = Encoding.UTF8
Dim enc3 As Encoding = Encoding.UTF32
Dim enc4 As Encoding = Encoding.BigEndianUnicode
Dim text As String = enc.GetString(byteArray)
Dim text1 As String = enc1.GetString(byteArray)
Dim text2 As String = enc2.GetString(byteArray)
Dim text3 As String = enc3.GetString(byteArray)
Dim text4 As String = enc4.GetString(byteArray)
Return text
End Function
Thanks
Mjcm
Last edited by a moderator: