推荐答案

It seems that this API has changed

现在只要用这个:string.toUtf8(start, end)

https://github.com/JetBrains/kotlin-native/commit/cba7319e982ed9ba2dceb517a481cb54ed1b9352#diff-45a5f8d37067266e27b76d1b68f01173

Legacy version:

使用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)

here.

如果通过互操作C API,字节数组大约为CPointer<ByteVar>,请在Kotlin Native中使用.toKString()

Kotlin相关问答推荐

在没有外部 map 的情况下转换列表项

如何检测一个值是否是Kotlin中的枚举实例?

列表在 android WebView 中没有正确迭代

Kotlin supervisorScope 即使包裹在 try catch 中也会失败

Kotlin 可空泛型

Kotlin:使用另一个列表和字母顺序对列表进行排序的有效方法

parallelStream()和asSequence().asStream().parallel()之间的区别

为空数组添加值

这是什么 Kotlin 类型:(String..String?)

Kotlin:如何使用第一个参数的默认值进行函数调用并为第二个参数传递一个值?

基类中的 ViewModelProviders.get(...)

Kotlin 顶级函数与对象函数

Kotlin Compose,在行中对齐元素

将 @Component.Builder 与构造函数参数一起使用

在 Kotlin 中实现 (/inherit/~extend) 注解

如何在Kotlin中使方法param可变?

将 Double 转换为 ByteArray 或 Array Kotlin

Kotlin - 如何获取注释属性值

Kotlin反射不可用

RxJava - 每秒发出一个 observable