I'm trying to convert an string to its integer value in Kotlin, using the toInt() function that i found in this answer, but I'm getting the ascii value instead.
What I'm doing wrong?
var input = "8569 2478 0383 3437"
val regex = "[^0-9]".toRegex()
var value = regex.replace(input, "")
val iterator = value.iterator()
var sum : Int = 0
var v : Int
for((index, value) in iterator.withIndex()){
if(index % 2 == 0){
var v = value.toInt() * 2
if(v > 9) v -= 9
print("$v:$value ")
sum += v
}else{
print("$value ")
sum += value.toInt()
}
}
executing this code above, this is the printed numbers
103:8 5 99:6 9 91:2 4 101:7 8 87:0 3 103:8 3 93:3 4 93:3 7
and I was expecting some like this
8:8 5 6:6 9 2:2 4 7:7 8 0:0 3 8:8 3 3:3 4 3:3 7