如果我有下一个字符串模板:
String test_template = ""%1$s" (%2$s) (%3$s)";
有没有什么方法可以只使用第三个参数来格式化它?
MessageFormat.format(test_template, *here put only 3rd parameter*);
您可以尝试:
String test_template2 = "{0} {1} {2}";
System.out.println(MessageFormat.format(test_template2,"first","second", "third"));
System.out.println(MessageFormat.format(test_template2,"","", "third"));
输出为:
"第一、第二、第三"
"第三"
希望帮助了你!
如果你想使用命名占位符,你可以在这里阅读