简体   繁体   中英

How to add something into string that read by String.xml?

I used this:

String message += getResources().getString(R.string.string1) + "some more word...";

and I wanted to send this string via sms, but it is not working. It works fine without the string resource. Am I missing something?

@forpas answer is absolutely correct, but you can also concat string resource this way.

<string name="name">Name %s</string>

String nameText =  getString(R.string.name,"khemraj");

When you use += operator with a String the result is a concatenation of the previous value of the String with some new String .
When you define a String variable like this:

String s;

the variable s is not initialized, so this:

s+="something";

is not allowed.

So instead of

String message += getResources().getString(R.string.string1) + "some more word...";

do

String message = getResources().getString(R.string.string1) + "some more word...";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM