I was writing my own file downloader but when I converted the byte array to string it changed length.
I was using the "UTF8" charset in the byte converter functions.
As a simple test I tried this...
It seems that "UTF8" charset requires 2 bytes when representing ordinal values (characters) greater than ordinal 127. I always thought UTF8 would always be within 1 byte per character.
To correct this I am now using "ASCII" as the charset and it all seems fine.
Does anyone have insight into UTF8 to help me understand why this is so?
I was using the "UTF8" charset in the byte converter functions.
As a simple test I tried this...
B4X:
Sub AppStart (Args() As String)
Dim conv As ByteConverter
Dim A As String = "Hello World" & Chr(255)
Dim B() As Byte = conv.StringToBytes(A,"UTF8")
Dim C As String = conv.StringFromBytes(B,"UTF8")
Log("A String = " & A.Length)
Log("Byte array = " & B.Length)
Log("C String = " & C.Length)
End Sub
It seems that "UTF8" charset requires 2 bytes when representing ordinal values (characters) greater than ordinal 127. I always thought UTF8 would always be within 1 byte per character.
To correct this I am now using "ASCII" as the charset and it all seems fine.
Does anyone have insight into UTF8 to help me understand why this is so?