1. string.xml文件
<resource>
<string name="number">第%1$d次</string>
<string name="number2">我是%1$s,我来自%2$s</string>
</resource>
2. %1$d 为整型
例子:
int age = 3;
String ageFormat = getResources.getString(R.string.number);
String finalAge = String.format(ageFormat , age);
输出结果:第3次
3. %1$s 为字符串型
例子:
String name = "小明";
String city = "厦门";
String infoFormat = getResources.getString(R.string.number);
String finalInfo = String.format(infoFormat , name , city);
输出:我是小明,我来自厦门。
参考:http://blog.csdn.net/wop_niaoren19870227/article/details/7090620