AnyCompiler

Strings

A $ inside a string literal inserts a variable's value directly — $name — or, with braces, a full expression — ${a + b}. This is built into every string literal, with no special prefix character needed the way C#'s interpolated strings need a leading $ before the opening quote.

fun main() {
    val name = "world"
    val greeting = "Hello, $name!"
    println(greeting)
    println(greeting.length)
}
Output
Hello, world!
13

Next: classes and objects — Kotlin's concise primary-constructor syntax.

Practice exercise

Given val name = "Kotlin", use a string template to print "Learning Kotlin today".