s, f and raw Interpolators
Embed values in strings.
What Is Interpolation?
String interpolation lets you embed values directly inside a string literal.
Instead of joining pieces with +, you put a prefix letter before the quotes and reference variables inside. Scala has three built-in interpolators: s, f, and raw.
val name = "Ada"
println(s"Hello, $name!")The s Interpolator
The s interpolator is the most common. Put s before the opening quote, then use $variable to insert a value.
It reads more clearly than concatenation with +.
val count = 3
println(s"You have $count messages")All lessons in this course
- String Basics
- s, f and raw Interpolators
- Common String Methods
- Multiline Strings