Multiline String Literals in Kotlin
Multiline String Literals in Java have always been clumsy and full of + operators for line-breaks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fun indentedStringLiteral() =
"""
First Line
Second Line
Third Line
"""
fun unindentedStringLiteral() =
"""
First Line
Second Line
Third Line
""".trimIndent()
fun main(args: Array<String>) {
println(indentedStringLiteral())
// First line
// Second Line
println(unindentedStringLiteral())
//First line
//Second Line
//Third line
}
In Kotlin you just have to define multiline strings in triple quotes and even get rid of indents.