It would work something like this
someUtility.replace ("Hello, my name is {1}. What开发者_运维技巧 is your {2}?", "Mark", "name");
String.format("Hello, my name is %1$s. What is your %2$s?", "Mark", "name");
or if you will just use each once in order:
String.format("Hello, my name is %s. What is your %s?", "Mark", "name");
Look at MessageFormat:
MessageFormat.format("Hello, my name is {0}. What is your {1}?", "Mark", "name");
Usually I prefer String.format
or System.out.printf
though for c-style formatting (sort of), as Matthew suggested.
If you want to use Spring the Resource Bundles will give you the actual exact style of replacement that you have displayed. You can see some examples here: http://www.mkyong.com/spring/spring-resource-bundle-with-resourcebundlemessagesource-example/
精彩评论