Avatar ·

How to work with strings in Kotlin?

Hello colleagues!

I recently started learning Kotlin after Java and encountered some peculiarities with working with strings. In Java, I was used to using methods like substring(), concat(), and StringBuilder, but in Kotlin, as I understand, it's a bit different. For example, I'm trying to concatenate several strings with spaces and output the result in uppercase.

Here's what I tried:
fun main() {\n    val firstName = "Ivan"\n    val lastName = "Petrov"\n    // Trying to concatenate\n    val fullName = firstName + " " + lastName\n    println(fullName.toUpperCase())\n}

This works, but I've heard that in Kotlin there are more idiomatic ways, for example, plus() or string templates. I also want to understand how to properly trim a string, e