https://kotlinlang.org logo
Title
d

Diaa Jad

12/02/2017, 11:46 PM
I might be overlooking an obvious solution, but how to convert a
char
to an
Int
?
var.toInt()
returns the ASCII value of the character.
s
d

Diaa Jad

12/03/2017, 12:46 AM
Thanks. I'm actually subtracting 48 from the value, but was hoping for a neater solution. Good idea of creating an advent-of-code group btw 🙂
a

adam-mcneilly

12/03/2017, 12:54 AM
So what I ended up doing in my final solution was just
'4'.toString().toInt()
because I felt like subtracting '0' was not immediately obvious. There's also a youtrack issue for a feature request for a
char.asDigit()
method.
d

Diaa Jad

12/03/2017, 1:02 AM
Right, it is a bit cleaner. Anyway, I hope they add the extension method that you suggested. See you at the advent-of-code channel 😉
a

Andreas Sinz

12/03/2017, 11:38 AM
@Diaa Jad there is
Character.toNumericInt(char)
from the java stdlib
d

Diaa Jad

12/03/2017, 5:58 PM
@Andreas Sinz thanks, I'll try that.