从字符串Kotlin中提取数字 [英] Extract numbers from a string kotlin
本文介绍了从字符串Kotlin中提取数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
String.replaceAll
未运行,并且在Kotlin中不受支持.因此,我建议一个演示示例,希望对您有所帮助.
String.replaceAll
is not running and is unsupported in Kotlin. So I suggest a demo example, I hope it help.
var string = "vsdhfnmsdbvfuf121535435aewr"
string.replace("[^0-9]".toRegex(), "")
推荐答案
您还可以利用Kotlin的String.filter:
You could also take advantage of Kotlin's String.filter:
var string = "vsdhfnmsdbvfuf121535435aewr"
var result = string.filter { it.isDigit() }
我是从这里得到的: https://stackoverflow.com/a/57316352
这篇关于从字符串Kotlin中提取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文