【发布时间】:2013-10-04 20:46:01
【问题描述】:
我有一个如下形式的字符串,例如 -:
String str = "The game received average review scores of 96.92% and 98/100 for the Xbox 360 version";
我希望输出如下 -:
Output = "The game received average review scores of % and / for the Xbox version"
并且我希望能够过滤掉字符串中的任何数字,无论是十进制数还是浮点数,我尝试使用蛮力的方式来执行此操作 -:
String str = "The game received average review scores of 96.92% and 98/100 for the Xbox 360 version";
String newStr = "";
for(int i = 0 ; i < str.length() ; ++i){
if(!Character.isDigit(str.charAt(i)))
newStr += str.charAt(i);
}
System.out.println(newStr);
但这并没有解决我的目的,如何解决这个问题?
【问题讨论】:
-
您可以查看this answer,这与您要查找的内容基本相反。通过一些调整,您可以使用它。