0

With Log4J I can compile a string easily with params:

log.error("My string with a {} and another one {}",param1,param2);

Is there something to compile a String with the same way instead of create a StringBuilder or concat strings?

String mystr=compileString("My string with a {} and another one {}",param1,param2);
Tobia
  • 9,165
  • 28
  • 114
  • 219
  • 2
    You could use `String mystr = String.format("My string with a %s and another one %s", param1, param2);` where `%s` indicates a parameter, like you would use `{}` with log4j – Lino Mar 26 '20 at 12:12
  • In addition to String.format, also take a look `java.text.MessageFormat`. The format less terse and a bit closer to the C# example you've provided and you can use it for parsing as well... see answer ti earlieer question: https://stackoverflow.com/a/6432100/5427593 – y_ug Mar 26 '20 at 12:19

0 Answers0