A: str.replaceAll("[^0-9]", "") B: str.replaceAll("\\D+","") C: public static String stripNonDigits( final CharSequence input /* inspired by seh's comment */){ final StringBuilder sb = new StringBuilder( input.length() /* also inspired by seh's comment */); for(int i = 0; i < input.length(); i++){ final char c = input.charAt(i); if(c > 47 && c < 58){ sb.append(c); } } return sb.toString();}
http://stackoverflow.com/questions/4030928/extract-digits-from-a-string-in-java
沒有留言:
張貼留言