赞
踩
动态替换字符串内容的方法
java.text.MessageFormat
String str = “this is a test!”;
System.out.println(MessageFormat.format(“MessageFormat方法:{0}这是{1}的使用”, str ,”占位符”));
java.lang.String.replace
String str = “难道这个可以?{0}这是{1}的使用”;
str = str.replace(“{0}”,”this is a test!”);
str = str.replace(“{1}”,”占位符”);
System.out.println();
第二种方法比较笨,动态替换字符串用的地方比较多,例如批量给不同用户发短信、发邮件。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。