String level = "INFO";
String stamp = "2013-04-26";
String message = "Log me, please!";
String template = "[%LVL%] - %STAMP%\n%MSG%";
String log = template.replaceAll("%LVL%", level);
log = template.replaceAll("%STAMP%", stamp);
log = template.replaceAll("%MSG%", message);
System.out.println(log);
这打印:
[%LVL%] - %STAMP%
Log me, please!
为什么第 3 个replaceAll("%MSG%", message);
有效,但第 2 个无效?