而在Java中使用的MessageFormat类通过不同的变量在一个字符串地使用MessageFormat,大括号{}
System.out.println(MessageFormat.format("I want to resolve this statement "{ {0}, {1} }", "this", "this"));
当您打印这个它会显示 - > {{0},{1}和意志由于缠绕大括号而无法通过值解析参数。
而在Java中使用的MessageFormat类通过不同的变量在一个字符串地使用MessageFormat,大括号{}
System.out.println(MessageFormat.format("I want to resolve this statement "{ {0}, {1} }", "this", "this"));
当您打印这个它会显示 - > {{0},{1}和意志由于缠绕大括号而无法通过值解析参数。
我正面临着这个问题,我想与大群人分享。 因此,为了解决同一个,它环绕单引号:
“{ '{0}', '{1}'}”
你想要的是这样的:
System.out.println(MessageFormat.format("I want to resolve this statement '{'{0}, {1}'}'", "this", "this"));
输出:
我想解决这个声明{此,}
同意迈克尔,但不知何故,我没有找到这种解决方案在堆栈流量...想与大集团分享。这些大括号会阻止变量 –
请更改字符串如下─
System.out.println(MessageFormat.format("I want to resolve this statement {0}, {1}", "this", "this"));
现在输出将原样
I want to resolve this statement this, this
花括号将与该被转换PARAMATERS
的确认感谢Sanjeev,但在我的情况下,我们无法移除相互冲突的外部大括号,因此我得出了通过使用' –
即线将不编译。 –
它不能解析参数 –
您是否阅读过'format'方法的Javadoc? –