Working with text
In the previous sections, we have explored numerous examples of working with text. After all, it is essential to utilize strings to output something as simple as “Hello Kotlin”. Attempting to achieve this without using a string would be both awkward and inconvenient.
In this section, we will delve into more advanced features that enable efficient manipulation of text.
String interpolation
Now, let’s assume we want to print the results from the previous section.
Firstly, Kotlin provides a convenient println()
standard function that simplifies the usage of the bulkier System.out.println
command from Java. We saw this when we looked at the Hello World
example.
Moreover, Kotlin supports string interpolation using the ${}
syntax, as seen in one of the previous examples. Let’s revisit the previous example:
val hero = "Batman"
println("Archenemy of $hero is ${archenemy(hero)}")
Executing the above...