无法从strings.xml 中正确显示卢比符号

时间:2021-08-01 15:20:16

标签: android string kotlin symbols

所以这很好用:

strFoo = "\u20B9" + strBar

但这没有

strFoo = R.string.rupee_symbol.toString() + strBar  //.toString() is required

//R.string.rupee_symbol.toString() evaluates to some random number 2131755148... which I believe is a character array... 

strings.xml

<string name="rupee_symbol">\u20B9 </string>

我不明白为什么它会这样,看起来是一样的......!

2 个答案:

答案 0 :(得分:1)

你不应该用字符串资源来连接字符串,你可以使用占位符:

<string name="rupee_symbol">\u20B9%s</string>

并使用:

strFoo = resources.getString(R.string.rupee_symbol, strBar)

答案 1 :(得分:1)

使用 getString(R.string.rupee_symbol) 代替 R.string.rupee_symbol.toString()

For example- 
String strBar = String.valueOf(100);
    String strFoo = getString(R.string.rupee_symbol)+strBar;
    textView.setText( strFoo);