谁能帮我按数字拆分字符串 例如:“I Need 5000 points”是我想要从该字符串中提取“5000”的字符串。
我尝试了很多方法,比如:
//split the string by RegExp:
String array = string.split(".*\\d.")
我得到了输出,但它不是我所期望的
输出:
array[0] = ""
array[1] ="points
谁能帮我找到合适的解决方案?
最佳答案
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher("I Need 5000 points");
while (matcher.find()) {
System.out.println(matcher.group());
}
关于java - 按数字拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18914904/