判断尾数是不是数字:3位

String code = new String("abc123号");
code=code.replace("号", "");
Pattern pattern = Pattern.compile("\\d+$");
Matcher matcher = pattern.matcher(code);
if(matcher.find()){
int num=Integer.parseInt(matcher.group());
num++;
code=code.substring(0,code.length()-matcher.group().length());
code=code+num;
}else{
System.out.println("字符串code不是以数字结尾的");
}
}

 

posted @ 2019-04-16 16:59  霸气小青年  阅读(243)  评论(0编辑  收藏  举报