0Pricing
Kotlin Academy · Lesson

String Templates: $variable and ${expression}

Embed variables and expressions inside strings using template syntax.

What Are String Templates?

String templates let you embed values directly into a string using $ for simple variables and ${...} for full expressions.

Embedding a Variable

Prefix a variable name with $ inside a string. Kotlin substitutes its value at runtime.

fun main() {
    val name = "Ada"
    println("Hello, $name!") // Hello, Ada!
}

All lessons in this course

  1. String Basics: Literals, Escape Sequences & Length
  2. String Templates: $variable and ${expression}
  3. Raw Strings and Triple Quotes
  4. Key String Functions: trim, split, replace, contains
← Back to Kotlin Academy