Is there a way to escape curly braces within String.format?
E.g. if I want to get the following output:
{777}
I'd expected {{ would do the job but this code throws an exception:
String.format('{{{0}}}', new String[] { String.valueOf(777) });
can't parse argument number: {{0}}
Thanks in advance!
Best Answer
This is how this is done
produces
{777}
SFDC
String.format
(also used by VFapex:outputtext
) uses the JavaMessageFormat
class. And braces are escaped by enclosing in single quotes, which in apex must also be escaped by backslash.See https://stackoverflow.com/questions/1187093/can-i-escape-braces-in-a-java-messageformat