toByteArray
Encodes the contents of this string using the specified character set and returns the resulting byte array.
inline fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray(source)
fun main() {
val text = "Hello, Kotlin!"
val bytes = text.toByteArray(Charsets.UTF_8)
println(bytes.joinToString(prefix = "[", postfix = "]") { it.toString() })
}