Android Question GetBytes returns length longer than string

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have a string that I do a
B4X:
Dim InString          as String
Dim StringBytes() as Byte = InString.GetBytes("UTF8")

The length of StringBytes is longer than InString

If I do GetBytes("ISO-8859-1") then the lengths are equal.

Why does UTF8 return more bytes?

BobVal
 

KMatle

Expert
Licensed User
Longtime User
UTF8 uses 1-4 bytes to represent a single char :D 8 Bits = 1 byte -> so you could only represent 256 different values (= chars). That's why UTFx was created. Think about all the languages in the world (liker German with the special chars äöüß) or emoticons in WhatsApp&Facebook.
 
Upvote 0
Top