判斷尾數是否是數字: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不是以數字結尾的");
}
}code

相關文章
相關標籤/搜索