Java string formatting

I have a properties file with lines inside, formatted like this:

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 these {0} and {1} using some standard APIs, or do I need to create some code to parse these strings

+3
source share
2 answers

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 want, and not just two.

+10
source

Source: https://habr.com/ru/post/1726529/


All Articles