为什么要从 strings.xml 中删除第一个 space

Why remove the first space from strings.xml

当我从 string.xml 调用某些东西时,我得到的更少,删除第一个 space。为什么?

<string name="s_basket_hun"> kosara</string>
<string name="s_basket_en">s basket</string>//removed the apostrophe

val cellValue = CustomerName + resources.getString(R.string.s_basket_hun)

我得到的只是“kosara”而不是“kosara”

可能会有一些通配符,比如 在 html

这就是 Android 资源系统的工作原理。

如果要保留尾随空格,可以将值括在双引号中,例如

<string name="s_basket_hun">" kosara"</string>

正常查看参考https://developer.android.com/guide/topics/resources/string-resource#escaping_quotes

Whitespace collapsing and Android escaping happens after your resource file gets parsed as XML. This means that     (space, punctuation space, Unicode Em space) all collapse to a single space (" "), because they are all Unicode spaces after the file is parsed as an XML. To preserve those spaces as they are, you can either quote them ("    ") or use Android escaping ( \u0032 \u8200 \u8195).

所以你有三个选择

1- 使用 "

<string name="s_basket_hun">" kosara"</string>

2- 使用 HTML 代码 &quot;(与 " 相同)

<string name="s_basket_hun">&quot; kosara&quot;</string>

3- 通过代码添加 space

val yourString = resources.getString(R.string.s_basket_hun)
val cellValue = "$CustomerName $yourString"

资源trim即白space。我建议你 to.use 这而不是连接客户名称和字符串

<string name="s_basket_en">%s basket</string>

val cellValue = resources.getString(R.string.s_basket_hun, CustomerName)

但是如果你仍然想那样使用你可以使用这个:

<string name="s_basket_en">&#160;kosara</string>

你可以像这样得到你的字符串,但是 Android Studio 希望你使用第一个字符串。

val cellValue = "$CustomerName ${resources.getString(R.string.s_basket_hun)}"