I might be overlooking an obvious solution, but ho...
# getting-started
d
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
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
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
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
@Diaa Jad there is
Character.toNumericInt(char)
from the java stdlib
d
@Andreas Sinz thanks, I'll try that.