Is there a kotlin only replacement for the java me...
# getting-started
m
Is there a kotlin only replacement for the java method
Character.getNumericValue()
? It would be useful in kmp but i can't seem to find one.
j
Depends on what you need. There is Char.digitToInt but it doesn't handle roman numerals like
\u216C
, while Java's method does. If you only need digits in the
0-9
range (or
a-z
range in bases > 10), then
digitToInt
should be enough
m
digitToInt
works for numbers only. the getNumericValues actually returns the full width number for A-Z which i am looking for. so
A
is
10
etc...
t
A colleague of mine wrote a blogpost about this: https://blog.jdriven.com/2019/10/converting-char-to-int-in-kotlin/
m
thanks. i actually found this blog post but it describes to use getNumericValues which i can not use in KMP
for a simple solution i mapped the chars manually to the supported range in need
t
My apologies then 🙂 happy you found a solution!
m
no worries. thanks for chipping in. maybe your colleague finds a better solution for KMP as well ;)
i
digitToInt  works for numbers only. the getNumericValues actually returns the full width number for A-Z which i am looking for. so A is 10 etc...
You need to specify
radix
parameter > 10 to work with digits A-Z.