格式化输出

·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;

       }

你可能感兴趣的:(String)