1.使用正则删除非数字
str = str.replaceAll("\\D+","");
2.Google Guava
CharMatcher.inRange('0','9').retainFrom("123-456-789")
或
String input = "My phone number is 123-456-789!";
String output = CharMatcher.is('-').or(CharMatcher.DIGIT).retainFrom(input); // output 123-456-789
最新评论
谢谢
百度网盘的提取密码不对
哪个国家成功率高一点?换了十几个了
有微信吗?有偿教我一下呗