String ageDesc = "3岁3个月";
//正则表达式,用于匹配非数字串,+号用于匹配出多个非数字串
String regEx="[^0-9]+";
Pattern pattern = Pattern.compile(regEx);
//用定义好的正则表达式拆分字符串,把字符串中的数字留出来
String[] cs = pattern.split(ageDesc);
if(ageDesc.indexOf("年")>-1) {
AgeDesc.setAttribute("value", inp.getAge());
}else if(ageDesc.indexOf("月")>-1) {
AgeDesc.setAttribute("value", cs[0]);
}else if(ageDesc.indexOf("天")>-1){
AgeDesc.setAttribute("value",cs[0]);
}
05-06
2724
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交