本文方法及代码示例基于 Kotlin 2.1.20 Released
code
所在包 kotlin.code
,其相关用法介绍如下:
用法:
<code class="kotlin">inline val Char.code: Intcode>
- 返回此 Char 的代码。
- 一个 Char 的代码是构造它的值,以及与这个 Char 对应的 UTF-16 代码单元。
示例:
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val string = "0Azβ"
println(string.map { it.code }) // [48, 65, 122, 946]
//sampleEnd
}
// 输出
[48, 65, 122, 946]