Is there a "pure" Kotlin way to convert a UByteArr...
# announcements
s
Is there a "pure" Kotlin way to convert a UByteArray into a UTF-8 string? Thanks! Edit: If there's no built-in support for this, can I just convert my array (UByteArray -> ByteArray) and then call
decodeToString
on it?
s
I don’t think you’ll want to convert from UByte to Byte unless you somehow don’t care about truncation or sign shenanigans
e
call String(ByteArray, Charset)
but there’s undefined behavior if the array contains invalid sequence
i
You can reinterpret an UByteArray as a ByteArray (by calling
asByteArray()
on it) and then call
decodeToString()
s
Hmm, I hadn't seen
asByteArray()
yet. Might be more adequate then the
toByteArray()
I used.