原文:http://www.educity.cn/wenda/179253.html
1、整型
在xml文件中:
<resources>
<string name="old">这位小姐今年%1$d岁了</string>
</resources>
在java代码中的使用:
String ageFormat = getResources().getString(R.string.old);
String finalFormat = String.format(ageFormat,22);
%1表示第一个需要替换的地方,%d表示替换成整型。如果有两个需要替换的地方,则写成%2%d类似。
2、string型
在xml文件中:
<resources>
<string name="info">我的名字叫%1$s,我来自%2$s</string>
</resources>
在java代码中:
String inforFormat = getResources().getString(R.string.info);
String finaleFormat2 = String.format(inforFormat,"张三","福建");