如何把变量中字符串资源? [英] How to put variable inside string-resources?

查看:153
本文介绍了如何把变量中字符串资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能把字符串资源的内部变量?如果是的 - 我如何使用它们

我需要的是以下内容:

<字符串名称=next_x_results>接着%X结果片剂; /串>

和把一个int代替%X的。

解决方案

 <字符串名称=meatShootingMessage>您出手%1 $ D斤肉<!/串GT ;


INT numPoundsMeat = 123;
。字符串strMeatFormat = getResources()的getString(R.string.meatShootingMessage);
字符串strMeatMsg =的String.Format(strMeatFormat,numPoundsMeat);
 

例子取自这里

Is it possible to put variables inside string-resources? And if yes - how do i use them.

What i need is the following:

<string name="next_x_results">Next %X results</string>

and put an int in place of the %X.

解决方案

<string name="meatShootingMessage">You shot %1$d pounds of meat!</string>  


int numPoundsMeat = 123;
String strMeatFormat = getResources().getString(R.string.meatShootingMessage);
String strMeatMsg = String.format(strMeatFormat, numPoundsMeat);

Example taken from here

这篇关于如何把变量中字符串资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆