我想弄清楚如何从我的字符串中删除找到的匹配项。所以我的代码示例目前看起来像这样:
public void checkText() {
String helper = "985, 913, 123, SomeotherText, MoreText, MoreText";
Pattern pattern = Pattern.compile("\\b\\d{3}");
Matcher matcher = pattern.matcher(helper);
while (matcher.find()) {
String newtext = "Number: " + matcher.group() + "\n"+ newtext;
helper.replaceAll(matcher.group(),"");
}
newtext = newtext + "________________\n"+ helper;
editText.setText(newtext);
}
所以我的输入字符串是:985, 913, 123, SomeotherText, MoreText, MoreText
运行代码后我想看到的是:
Number: 985
Number: 913
Number: 123
________________________
SomeotherText, MoreText, MoreText
谁能告诉我我当前的代码有什么问题?
饮歌长啸
慕的地10843
相关分类