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
- String Basics: Literals, Escape Sequences & Length
- String Templates: $variable and ${expression}
- Raw Strings and Triple Quotes
- Key String Functions: trim, split, replace, contains