My question is similar to this question, which asks how to substitute properties into a string such as
Transfer {0} from {1} to {2} on {3}
The answer to that question, the MessageFormat class, won’t work with my needs. I’d like to substitute named parameteres into a string like:
The {weather} in {location} stays mainly in the {terrain}.
or perhaps
The ${weather} in ${location} stays mainly in the ${terrain}.
Am I lucky enough that there already exists a class like MessageFormat to help with that or should I cobble together something on my own to do it? Ant does this with build.xml – but short of lifting their code I’m wondering if there is already an existing class.
May I suggest creating a new class called
CustomMessageFormat:That all that does is replace all your {sometext} tokens with sequential ones ({1}, {2} etc.) as required by
MessageFormat.formatmethod.The you can simply use:
This is, of course, a rough example, but I hope you get the idea.