This is my code:
fun main(){
val str = "123"
println(str.toInt()) // 123
println(str[1].toInt()) // 50 ???
}
I want number 2. But it's result number 50.
I didn't want ASCII code number.
How can I get a solution?
If you want to get the second character in the String, you can do
println(str[1])
And if you want to convert the second character to an Int, then you should do
println(str[1].toString().toInt())
Please note that toInt() can throw a NumberFormatException.
str[1]. What does that say?