本文介绍了如何在字符串的末尾和/或开头保留空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将我的资源/值文件中的这两个字符串连接起来:

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>

我这样做:

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();

但是第一个字符串末尾和第二个字符串开头的空格已经消失了(显示Toast时)...

But the spaces at the end of the first string and at the beginning of the second stringhave disappeared (when the Toast is shown) ...

我该怎么办?

我猜答案在此文档中的某处链接

还是类似于对使用 &amp ; 字符??

or is it something like using &amp ; for the "&" character ??

推荐答案

即使您使用字符串格式设置,有时您仍然需要在字符串的开头或结尾使用空格.对于这些情况,使用\转义和xml:space属性都无济于事.您必须将HTML实体&#160;用于空白.

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 &#160; for a whitespace.

&#160;用于不可中断的空白.
&#032;用于常规空间.

Use &#160; for non-breakable whitespace.
Use &#032; for regular space.

这篇关于如何在字符串的末尾和/或开头保留空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 17:47
查看更多