is it possible to ignore new lines in a multiline ...
# getting-started
l
is it possible to ignore new lines in a multiline string? In Java, one can use
\
to do so. Wondering if Kotlin has something similar
Copy code
String a = "This is a long string";
String b = """
     This is a \
     long string""";
a.equals(b) // true
j
I don't think there is any such thing syntax wise in Kotlin. However, you can post-process the string using
.replace("\n", "")
. This won't help with indents, though, which seems to also be removed in your Java example (if this behaves as you said it does). For indents, you have other utilities in Kolin called
trimIndent
and
trimMargin
l
gotcha i was thinking i have to do something like that
yea if you put the closing
"""
in the same final line it strips out the indents in java (i think)
­čĹî 1
n
One workaround is to use
Copy code
val b = """
    This is a 
    """.trimIndent() + """
    long string
    """.trimIndent()