我正在开发 Android 项目,但我从服务器检索包含所有本地化字符串的 .xml
文件。我面临一个问题,因为当字符串可以包含参数时,该参数设置在双括号中,例如:
You have {{0}} dollar(s) on your account
我无法使用常规的String.format()
函数。我真的不知道如何解决这个问题,我应该创建一个自定义格式化程序吗?
编辑:字符串可以有多个参数
谢谢
最佳答案
使用String.replace()
而不是String.format()。
您还可以替换多个参数,例如,
String s = "{{0}} is friend with {{1}}";
s = s.replace("{{0}}","ABC");
s = s.replace("{{1}}","PQR");
关于java - 自定义格式字符串 : arguments in double brackets java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51741553/