我有以下形式實例的字符串 - :如何從java中的字符串中過濾出數字?
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);
但這並不解決purpos對我而言,如何解決這個問題?
你可能看看[這個答案](http://stackoverflow.com/a/19169192/1578604)這基本上是你正在尋找的相反。隨着一些調整,你可以使用它。 – Jerry