无法打印整个字符串值
Can't print whole string value
我想使用 kotlin 字符串多行,但我无法打印它的整个值。
我想像这样打印它的值:
println("In kotlin you can make multyLine string $text")
但是打印出来的只是第一行:
I/System.out: In kotlin you can make multyLine string First line
当我查找其余文本时,它位于 logcat 中,例如当我搜索 "Another line" 时,我找到了它:
I/System.out: Another line
我已经通过将它放在 textView 中来检查值是否正确 像这样
val textView:TextView = findViewById(R.id.text)
val text = """
|First line
|Another line
|one more
|and stop
""".trimMargin()
textView.setText(text)//I can see the full text
为什么我的字符串没有打印成一个文本块,而是按照我上面描述的方式打印?
基本上trimMargin()
转:
val text = """
|First line
|Another line
|one more
|and stop
""".trimMargin()
进入这个:
First line\n Another line\n one more\n and stop
和 println
是 System.out.println(message)
所以您将在 Logcat 中看到的是
I/System.out: In kotlin you can make multyLine string First line
I/System.out: Another line
I/System.out: one more
I/System.out:
and stop
因此您可以使用 Log.d(TAG, "In kotlin you can make multyLine string $text")
来在您的 Logcat 中获得此结果:
D/tag: In kotlin you can make multyLine string First line
Another line
one more
and stop
我想使用 kotlin 字符串多行,但我无法打印它的整个值。
我想像这样打印它的值:
println("In kotlin you can make multyLine string $text")
但是打印出来的只是第一行:
I/System.out: In kotlin you can make multyLine string First line
当我查找其余文本时,它位于 logcat 中,例如当我搜索 "Another line" 时,我找到了它:
I/System.out: Another line
我已经通过将它放在 textView 中来检查值是否正确 像这样
val textView:TextView = findViewById(R.id.text)
val text = """
|First line
|Another line
|one more
|and stop
""".trimMargin()
textView.setText(text)//I can see the full text
为什么我的字符串没有打印成一个文本块,而是按照我上面描述的方式打印?
基本上trimMargin()
转:
val text = """
|First line
|Another line
|one more
|and stop
""".trimMargin()
进入这个:
First line\n Another line\n one more\n and stop
和 println
是 System.out.println(message)
所以您将在 Logcat 中看到的是
I/System.out: In kotlin you can make multyLine string First line
I/System.out: Another line
I/System.out: one more
I/System.out: and stop
因此您可以使用 Log.d(TAG, "In kotlin you can make multyLine string $text")
来在您的 Logcat 中获得此结果:
D/tag: In kotlin you can make multyLine string First line
Another line
one more
and stop