我正在尝试使用ChoiceFormat显示除格式元素之外的引号的消息。使用该模式,引用不会打印,但使用编程方式,如在用于ChoiceFormat的Java文档中,它工作正常。有线索吗?
Object[] testArgs = { "Navin", 0 };
// Using Pattern
System.out.println(MessageFormat.format("You commented on {1,choice,0#{0}''s diary|1#many diaries}", testArgs));
// Creating programmatically
MessageFormat form = new MessageFormat("You commented on {1}");
double[] limits = { 0, 1 };
String[] part = { "{0}''s diary", "many diaries" };
ChoiceFormat cform = new ChoiceFormat(limits, part);
form.setFormatByArgumentIndex(1, cform);
System.out.println(form.format(testArgs));
给出输出:
您评论了Navins日记
您评论了Navin的日记
答案 0 :(得分:5)
放入另一组单引号,如:
System.out.println(MessageFormat.format("You commented on {1,choice,0#{0}''''s diary|1#many diaries}", testArgs));
这应该打印:
您评论了Navin的日记