I was playing with the kotlin-native samples.
I wonder how I could get String
from pinned
ByteArray. Just want to print it in the console.
Now just use this: string.toUtf8(start, end)
Use stringFromUtf8
/**
* Converts an UTF-8 array into a [String]. Replaces invalid input sequences with a default character.
*/
fun ByteArray.stringFromUtf8(start: Int = 0, size: Int = this.size) : String =
stringFromUtf8Impl(start, size)
See here.
And if the byteArray is like CPointer<ByteVar>
by interoperating C APIs, pleace use .toKString()
in Kotlin-Native