VB.NET encoding one character wrong
- by Nick Spiers
I have a byte array that I'm encoding to a string:
Private Function GetKey() As String
Dim ba() As Byte = {&H47, &H43, &H44, &H53, &H79, &H73, &H74, &H65, &H6D, &H73, &H89, &HA, &H1, &H32, &H31, &H36}
Dim strReturn As String = Encoding.ASCII.GetString(ba)
Return strReturn
End Function
Then I write that to a file via IO.File.AppendAllText.
If I open that file in 010 Editor (to view the binary data) it displays as this:
47 43 44 53 79 73 74 65 6D 73 3F 0A 01 32 31 36
The original byte array contained 89 at position 11, and the encoded string contains 3F.
If I change my encoding to Encoding.Default.GetString, it gives me:
47 43 44 53 79 73 74 65 6D 73 E2 80 B0 0A 01 32 31 36
Any help would be much appreciated!