例如,我有以下形式的字符串-:
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);
但这并不能解决我的目的,如何解决这个问题?