在文本视图中对从服务器作为 JSON 响应接收的字符串添加换行符


val desc = /* String Rec From Server ("one line n two line") */
product_description?.text = desc

我希望文本视图是

one line
two line

但我明白了

one line n two line

如果我将文本直接分配给"desc",它可以正常工作。但我希望它在从服务器收到时工作。

我认为您可以在 Kotlin 中使用三引号字符串来实现这一点,例如

val myString = """this is one line
                 *this is another line"""

如果将它们作为变量,您可能会做类似的事情

val s = """$var1 
          *$var2

抱歉,目前无法自己测试,但希望可以以某种方式提供帮助。

最新更新