encodeToByteArray
Encodes this string to an array of bytes in UTF-8 encoding.
expect fun String.encodeToByteArray(): ByteArray(source)
val text = "Hello, Kotlin!"
val bytes = text.encodeToByteArray()
println("Byte array: ${bytes.joinToString(", ") { it.toString() }}")
// If you need to convert it back to a String
val decoded = bytes.toString(Charsets.UTF_8)
println("Decoded string: $decoded")