1.判断是否为数字
//判断是否为数字
public static boolean isInteger(String str) {
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
return pattern.matcher(str).matches();
}
2. 获取数字并返回
//获取数字
private int getNumber(String aa){
String regEx="[^0-9]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(aa);
int b = 0;
if ( m.find() ){
b = Integer.parseInt(m.replaceAll("").trim());
}
return b;
}
3. 判断是否包含汉字
//是否包含汉字
public static boolean isContainChinese(String str) {
Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
Matcher m = p.matcher(str);
if (m.find()) {
return true;
}
return false;
}
4. 去掉多余的0
//去掉多余的"0"
public static String subZeroAndDot(String s){
if(s.indexOf(".") > 0){
s = s.replaceAll("0+?$", "");//去掉多余的0
s = s.replaceAll("[.]$", "");//如最后一位是.则去掉
}
return s;
}