Klitos Kyriacou
02/21/2025, 1:56 PMval str = StringBuilder("The value of your purchase is ").apply {
...do things...
append(things)
}.toString()
This would be neater if buildString
had an overload that takes a String
or CharSequence
parameter. Without it, we would have to do the above, or the even worse:
val str = buildString("The value of your purchase is ".length + 16) {
append("The value of your purchase is ")
...do things...
append(things)
}
Has anyone ever made a request for such a function and what was the outcome?Klitos Kyriacou
02/21/2025, 2:39 PMvar str = "Some long string"
if (condition1) str += "another string"
if (condition2) str += "and another"
To make str
into an immutable val
using something like this (if only buildString(string, block)
existed):
val str = buildString("Some long string") {
if (condition1) append("another string")
if (condition2) append("and another")
}
Joffrey
02/21/2025, 5:59 PMappend
.