Strings In Depth17 / 17
Up next

Encode to bytes

fun main() {
    val s = "héllo"
    // encode to UTF-8 bytes, then decode back
    val bytes = s.toByteArray(Charsets.UTF_8)
    val back = String(bytes, Charsets.UTF_8)
    println("${bytes.size} $back")
}
What you're solving

toByteArray and back with a charset