i want to extract numbers from string how can i do that in Kotlin ?
81aabf9d-844e-4086-9621-f3afed02e163
to
81984440869621302163
i want to extract numbers from string how can i do that in Kotlin ?
81aabf9d-844e-4086-9621-f3afed02e163
to
81984440869621302163
You can use String filter:
val text= "81aabf9d-844e-4086-9621-f3afed02e163"
val result = text.filter{it.isDigit()}
just use this extension function
fun String?.extractDigit(): Long {
if (this == null) {
return 0
}
var nums = this.replace("\\D+".toRegex(), "")
Log.i("extractDigit", nums)
if (nums.isEmpty())
return 0
return nums.toLong()
}