How to keep the spaces at the end and/or at the beginning of a String?
I have to concatenate these two strings from my resource/value files:
<string name="Toast_Memory_GameWon_part1">you found ALL PAIRS ! on </string>
<string name="Toast_Memory_GameWon_part2"> flips !</string>
I do it this way :
String message_all_pairs_found = getString(R.string.Toast_Memory_GameWon_part1)+total_flips+getString(R.string.Toast_Memory_GameWon_part2);
Toast.makeText(this, message_all_pairs_found, 1000).show();
But the spaces at the end of the first string and at the beginning of the second string have disappeared (when the Toast is shown) ...
What should I do ?
I guess the answer is somewhere here in this documentation link
or is it something like using & ;
for the "&" character ??
Even if you use string formatting, sometimes you still need white spaces at the beginning or the end of your string. For these cases, neither escaping with , nor
xml:space
attribute helps. You must use HTML entity  
for a whitespace.
Use  
for non-breakable whitespace.
Use  
for regular space.
I ran into the same issue. I wanted to leave a blank at the end of a resource string representing an on-screen field name.
I found a solution on this issue report : https://github.com/iBotPeaches/Apktool/issues/124
This is the same idea that Duessi suggests. Insert u0020
directly in the XML for a blank you would like to preserve.
Example :
<string name="your_id">Score :u0020</string>
The replacement is done at build time, therefore it will not affect the performance of your game.
本文档建议引用将起作用:
<string name="my_str_spaces">" Before and after? "</string>
链接地址: http://www.djcxy.com/p/90744.html
下一篇: 如何将空格保留在字符串的末尾和/或开头?