Saturday 25 November 2017

Kotlin: Convert character to Int

Char type provides toInt() method to convert a character to integer.

IntConverter.kt
fun main(args: Array<String>) {

 var myChar : Char = 'a'

 println("Value of myChar is : ${myChar}")
 println("Value of myChar in int is : ${myChar.toInt()}")
}

Output
Value of myChar is : a
Value of myChar in int is : 97


Previous                                                 Next                                                 Home

No comments:

Post a Comment