·MessageFormat
final MessageFormat str1 = new MessageFormat("{0}〔{1}〕{2}号"); System.out.println(str1.format(new String[]{"111","222","333"})); |
·DecimalFormat
DecimalFormat df = new DecimalFormat("0000"); String xh = df.format(gongwen.getBenyongzi()); |
·Pattern
public final static Pattern FA_WEN_ZI_HAO_PATTERN = Pattern.compile("^([//S//s]*)[//〔|//[]{1}([0-9]*)[|//]//〕]{1}[第]?([//S//s]*)号$"); |
public static String[] parseFaWenZiHao(String fawenzihao){ int patterCount = 3; String[] returnValue = new String[patterCount]; Matcher matcher = Constant.FA_WEN_ZI_HAO_PATTERN.matcher(fawenzihao); while(matcher.find() && matcher.groupCount() == patterCount){ for(int i=0;i<patterCount;i++){ returnValue[i] = matcher.group(i+1); } } return returnValue; } |