问题标签 [messageformat]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 如何转义 MessageFormat 模式字符串中的 { 字符?
我有一个如下的字符串。
ABC {A WELL-KNOWN MAGICIAN} 将在 {0} 表演 {1} 小时。
第一对花括号没有占位符。当我将此字符串传递给 MessageFormat.format(String, Object[]) 方法时,对象数组包含两个字符串以替换占位符 {0} 和 {1},我收到以下错误。
java.lang.IllegalArgumentException:所有参数标识符必须是非负数或遵循模式 ([:ID_Start:] [:ID_Continue:]*) 的字符串。
似乎正在为第一个占位符解析第一对大括号,并且由于它不是有效的占位符,因此会发生错误。
如何告诉 MessageFormat.format 忽略第一对花括号并与另外两个一起使用?