开发者

Java String formatting

I have a property-file with strings inside, formatted in this way:

audit.log.events.purged=The audit events were purged. {0} events were purged, {1} assets were deleted.

Is there a way to bind some values inside those {0} and {1}, using some standard APIs, or should I create some cod开发者_开发知识库e for parsing those Strings?


Java 1.4.2:

String formattedMessage = MessageFormat.format(message, new Object[]{parm1, parm2});

Java 1.5+:

String formattedMessage = MessageFormat.format(message, parm1, parm2);

In both cases you can have as many parameters as you wish, not just two.


You are looking for MessageFormat: http://java.sun.com/j2se/1.5.0/docs/api/java/text/MessageFormat.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜