Java 替换时动态参数替换单引号

Java 替换时动态参数替换单引号,java,Java,我使用任何字符串的动态值替换动态参数 我使用了以下代码: public static String setDynamicParameter(String text,Object[] values){ MessageFormat messageFormat = new MessageFormat(text); return messageFormat.format(values); } public static void main(String [] args) {

我使用任何字符串的动态值替换动态参数

我使用了以下代码:

public static String setDynamicParameter(String text,Object[] values){
    MessageFormat messageFormat = new MessageFormat(text);
    return messageFormat.format(values); 
}

public static void main(String [] args) {
    String text = "Test message 'test'";
    System.out.println(setDynamicParameter(text, null));
}
在上面的代码中,我没有使用任何动态参数进行测试

OUTPUT : Test message test
我面临的问题是:它取代了单一的quot

为什么它取代了单引号?

这来自:

在字符串中,一对单引号可用于引用除单引号以外的任意字符。例如,模式字符串“{0}”表示字符串“{0}”,而不是FormatElement。在整个字符串中,单引号本身必须由双引号“”表示


因为引号是MessageFormat的转义字符。只需阅读它的文档。你需要加倍报价。