【发布时间】:2010-08-13 15:38:52
【问题描述】:
考虑以下格式的字符串模板:
String template = "The credentials you provided were username '{0}' with password '{1}'";
替换变量字段的格式为 {n},其中 n 是从零开始的索引。
这是 Adobe Flex 中使用的模板格式,请参阅 StringUtil.substitute(...)。还有 .NET、IIRC。
由于我想重用 Flex 代码使用的模板,因此我正在寻找 Java 等价物。我知道String.format(...),但模板结构并不相同。
在 Java 中获得相同的“Flex 兼容”模板功能的最佳方式是什么?
基本上这是期望的最终结果:
assert(StringUtil.substitute(template, "powerUser", "difficultPassword") == "The credentials you provided were username 'powerUser' with password 'difficultPassword'");
【问题讨论】:
标签: java apache-flex string