Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1142

kotlin android bad conversion of UTF-8 characters

$
0
0

I am encountering a basic issue with kotlin android (API 29)

import kotlin.text.Charsets.UTF_8var buf = byteArrayOf(0xF0.toByte(), 0xa9.toByte(), 0xbd.toByte(), 0xbe.toByte())var s = String( buf, UTF_8)Log.e(TAG, "buf len ${buf.size} as UTF-8 : <$s8> len ${s8.length}")

After converting the string from byte buffer, I get string length = 2 (as if kotlin thinks the string is UTF-16), but of course the string length should be 1.No problem with Python!!

Output:

 buf len 4 as UTF-8 : <𩽾> len 2

I am a. it puzzled: How is that possible? How could kotlin string conversion be wrong?

Note that the UTF-8 F0A9BDBE is correct for the character 𩽾


Viewing all articles
Browse latest Browse all 1142

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>