toByteArray
Encodes the contents of this string using the specified character set and returns the resulting byte array.
Encodes the contents of this string using the specified character set and returns the resulting byte array.
import java.util.Locale import kotlin.test.* fun main() { //sampleStart val charset = Charsets.UTF_8 val byteArray = "Hello".toByteArray(charset) println(byteArray.contentToString()) // [72, 101, 108, 108, 111] println(byteArray.toString(charset)) // Hello //sampleEnd }
xxxxxxxxxx
val charset = Charsets.UTF_8
val byteArray = "Hello".toByteArray(charset)
println(byteArray.contentToString()) // [72, 101, 108, 108, 111]
println(byteArray.toString(charset)) // Hello
Thanks for your feedback!