Java MessageFormat fails to format specific string

695 views Asked by At

I have a constant declared as following:

protected static final String LOC_RC_ELT = "[id*='rcLine'][id$='paxIndex{0}']";

And then I use MessageFormat:

MessageFormat.format(LOC_RC_ELT, paxIndex)

In this case MessageFormat fails to format the string declared as constant:

enter image description here

This is not true for other cases like:

LOC_RC_SELECTED_TAB = "[id*=_rc-tabs{0}] .tabSelected"

This works just fine:

enter image description here

Why I'm getting this weird behavior ? and how can I solve it ?

Thanks in advance.

1

There are 1 answers

0
user85421 On

Weird behavior, but as specified.

Check the documentation:

Within a String, a pair of single quotes can be used to quote any arbitrary characters except single quotes. For example, pattern string "'{0}'" represents string "{0}", not a FormatElement. A single quote itself must be represented by doubled single quotes '' throughout a String.