gpt4 book ai didi

java - 使用 ChoiceFormat 模式显示报价

转载 作者:行者123 更新时间:2023-11-30 06:21:09 25 4
gpt4 key购买 nike

我正在尝试使用 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));

给出输出:

你评论了纳文斯的日记

你评论了Navin的日记

最佳答案

放入另一组单引号,如:

System.out.println(MessageFormat.format("You commented on {1,choice,0#{0}''''s diary|1#many diaries}", testArgs));

这应该打印:

您对 Navin 的日记发表了评论

关于java - 使用 ChoiceFormat 模式显示报价,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20852079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com