String str = "Java目前的发展史是由{0}年-{1}年"; String[][] object={new String[]{"\\{0\\}","1995"},new String[]{"\\{1\\}","2007"}}; System.out.println(replace(str,object)); public static String replace(final String sourceString,Object[] object) { String temp=sourceString; for(int i=0;i<object.length;i++){ String[] result=(String[])object[i]; Pattern pattern = Pattern.compile(result[0]); Matcher matcher = pattern.matcher(temp); temp=matcher.replaceAll(result[1]); } return temp; }
初级程序员
by: hasonger 发表于:2013-01-04 23:05:10 顶(1) | 踩(0) 回复
学习哈
网友回复
回复小蜜锋 : 学习学习!
顶(0) 踩(0) 2013-01-10 18:12:36
回复评论