Reputation: 1224
I want to take a Char value from the user but .toChar does not compile in my code
fun main (args:Array<String>){
var character:Char= readLine()!!.toChar()
println("your value is $character")
}
Error:(4, 38) Kotlin: Unresolved reference: toChar
Upvotes: 0
Views: 362
Reputation: 3105
Which char do you want?
This will return the first char of the String, since a String is essentially a CharArray.
fun main (args:Array<String>){
val character = readLine()!![0]
println("your value is $character")
}
Upvotes: 1