Colton Idle
02/19/2021, 5:35 PM,
between strings in a string builder.
I know joinToString
exists and it works great for arrays, but I basically want the same functionality for a string builder.
Here's what I'm currently doing (no commas yet):
topic.data.forEach {
myBuilder.append("${it.city} ${it.status}")
}
}
Maybe I'm missing something basic. ThanksVampire
02/19/2021, 5:40 PMStringBuilder
a fixed necessity?
If not you could for example do
topic.data.joinToString(',') { "${it.city} ${it.status}" }
nanodeath
02/19/2021, 5:44 PMStringBuilder
to joinTo
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/join-to.htmlVampire
02/19/2021, 5:48 PMStringBuilder
is Appendable
.
So then it would be topic.data.joinTo(myBuilder, ",") { "${it.city} ${it.status}" }
.Colton Idle
02/19/2021, 5:49 PMnanodeath
02/19/2021, 5:50 PMColton Idle
02/19/2021, 5:50 PMnanodeath
02/19/2021, 5:51 PMColton Idle
02/19/2021, 5:51 PMVampire
02/19/2021, 5:51 PMStringJoiner
in it 😄nanodeath
02/19/2021, 5:51 PMjoinToString
if you don't already have and need a builderColton Idle
02/19/2021, 5:58 PM