I've got a String like this:
Very long text ... ${ABC} ... very long text ... ${DEF} ...
...
very long text ... ${GHI} ... very long text ...
...
... and so forth ...
and I need to replace all these ${...}
with some value (say also such value can be very long) which is stored in a variable of type String
.
Until now I'm solving it like follows:
String finalString = templateString
.replaceAll("\\$\\{ABC}", abc)
.replaceAll("\\$\\{DEF}", def)
.replaceAll("\\$\\{GHI}", ghi)
...
but I'm sure it is not the best way of doing this.
I can't use String.format()
because the template variables are named.
Do you know any way of doing this (maybe using StringBuilder
?) without using external libraries?