gpt4 book ai didi

java - 包含单引号时 MessageFormat 不格式化

转载 作者:搜寻专家 更新时间:2023-10-30 20:59:20 29 4
gpt4 key购买 nike

我传递的文本是 {} 填充符和文本的组合。我正在尝试用一些值填充 {} 并尝试使用 MessageFormat。

String sss = "{0}SomeText{1}\'.{2}SomeText{2}SomeText{0}{0}SomeText{2}{0}SomeText{0}{1}SomeText{0}{2}{0}{0}{1}{0}{2}{0}{0}{2}{0}{0}{1}{0}{2}{0}";

Object[] testArgs = {"nits1", "Nits2","nits#"};

System.out.println(MessageFormat.format(sss,testArgs));

输出

nits1SomeTextNits2.{2}SomeText{2}SomeText{0}{0}SomeText{2}{0}SomeText{0}{1}SomeText{0}{2}{0}{0}{1}{0}{2}{0}{0}{2}{0}{0}{1}{0}{2}{0}

最佳答案

单引号必须使用双单引号进行转义:

String sss = "{0}SomeText{1}''.{2}S..."

关于java - 包含单引号时 MessageFormat 不格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10995725/

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