/**
*/
public class NumberUtils {
public static void main(String[] args){
String number = getNumberFromString("bjdf009djfd122");
System.out.println("number : " + number);
}
/**
* 从 String 中提取数字
* @param string
* @return
*/
public static String getNumberFromString(String string){
String str = string;
str = str.trim();
StringBuffer str2 = new StringBuffer();
if(str != null && !"".equals(str)) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) >= 48 && str.charAt(i) <= 57) {
String s = String.valueOf(str.charAt(i));
str2.append(s);
}
}
}
return str2.toString();
}
}
# 控制台输出:
009122
网友评论