将 int 元素转换为 char,然后再转换为字符串 Kotlin 错误?
Convert int element to char and then to string Kotlin error?
我正在尝试将一个 int 元素传递给一个 char,然后再传递给一个字符串,但没有成功(该字符串不显示任何内容)。这是我遇到问题的代码部分。任何帮助都非常有用,谢谢
private fun setFicha(view: ImageView, posicionFila: Int, posicionColumna: Int){
val texto = findViewById<TextView>(R.id.texto)
if(tablero[posicionFila][posicionColumna] == '-') {
total++
tablero[posicionFila][posicionColumna] = total.toChar()
texto.text = tablero[posicionFila][posicionColumna].toString()
}
checkGameOver()
}
要将 Char
转换回 Int
使用 code
属性:
49.toChar() // => '1' (Char)
49.toChar().code // => 49 (Int)
49.toChar().code.toString() // => "49" (String)
Char
Kotlin 中的类型表示一个 16 位的 Unicode 字符。代码 49 对应字符 '1'.
我正在尝试将一个 int 元素传递给一个 char,然后再传递给一个字符串,但没有成功(该字符串不显示任何内容)。这是我遇到问题的代码部分。任何帮助都非常有用,谢谢
private fun setFicha(view: ImageView, posicionFila: Int, posicionColumna: Int){
val texto = findViewById<TextView>(R.id.texto)
if(tablero[posicionFila][posicionColumna] == '-') {
total++
tablero[posicionFila][posicionColumna] = total.toChar()
texto.text = tablero[posicionFila][posicionColumna].toString()
}
checkGameOver()
}
要将 Char
转换回 Int
使用 code
属性:
49.toChar() // => '1' (Char)
49.toChar().code // => 49 (Int)
49.toChar().code.toString() // => "49" (String)
Char
Kotlin 中的类型表示一个 16 位的 Unicode 字符。代码 49 对应字符 '1'.