[英]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:
MessageFormat.format(LOC_RC_ELT, paxIndex)
In this case MessageFormat fails to format the string declared as constant:在这种情况下 MessageFormat 无法格式化声明为常量的字符串:
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.在String 中,一对单引号可用于引用除单引号之外的任意字符。 For example, pattern string
"'{0}'"
represents string"{0}"
, not a FormatElement .例如,模式字符串"'{0}'"
表示字符串"{0}"
,而不是FormatElement 。 A single quote itself must be represented by doubled single quotes''
throughout a String .单引号本身必须由整个String 中的双引号''
表示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.