Byte Array to String - Encoding question

MJCM

Member
Joined
Jun 17, 2004
Messages
22
Location
SE-Asia
Programming Experience
1-3
I have the following piece of code to convert a Byte Array to a String,
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
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
 
Last edited by a moderator:
I'll check it out.. what had puzzled me most was that I didnt get a mail note.. i just saw that someone had replied, clicked the mail link and got to the old thread, without the reply the mail notification purported.. I eventaully had to search the boards for some keywords. I wonder if there is a way for subscribed users to get notified when a thread is split, because it definitely didnt happen this time (and other times i seem to recall) :)
 
Back
Top