0

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.

Renaud is Not Bill Gates
  • 1,684
  • 34
  • 105
  • 191
  • 2
    Think it has something to do with the single quotes. What happens when `LOC_RC_ELT` is `"[id*='rcLine'][id$=paxIndex{0}]";`? Check this https://stackoverflow.com/a/189955/5675692 – Ashvin Sharma Mar 16 '20 at 13:05

1 Answers1

2

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.

user85421
  • 28,957
  • 10
  • 64
  • 87