3

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 code for parsing those Strings?

2 Answers 2

11

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Actually, it will work as MessageFormat.format(message, parm1, parm2); as well, cause it accepts enumerations.
Correct - I'm unfortunately still far too used to programming with 1.4's retrictions!
9

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.