简体   繁体   中英

Java MessageFormat fails to format specific string

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:

在此处输入图片说明

This is not true for other cases like:

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

This works just fine:

在此处输入图片说明

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

Thanks in advance.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM