Matyáš Vítek
08/27/2023, 1:29 PM"$variable"
instead of variable.toString()
as dumb as it looks?Sam
08/27/2023, 1:51 PMYoussef Shoaib [MOD]
08/27/2023, 3:47 PMtoString()
as a transformation (I don't have a better way of explaining it lol) then it's better. Generally string template is just better lol!ephemient
08/28/2023, 1:34 AMStephan Schröder
08/29/2023, 7:54 AMval xml: String = with(person) {
"""
<person>
<name>$name</name>
<birthday>${birthday.format()}</birthday>
<address>${address.toOneLine()}</address>
</person>
""".trimIndent()
}
Here a real life code example from my code bringing even more Kotlin String concatenation into the mix:
val mockServerUrl = buildString {
append(if (isSecure) "https" else "http")
append("://$host:$port")
}
Klitos Kyriacou
08/29/2023, 8:52 AMval mockServerUrl = "${if (isSecure) "https" else "http"}://$host:$port"
Stephan Schröder
08/29/2023, 9:20 AMbuildString
.