Multiline Strings
Use triple-quoted blocks.
What Are Multiline Strings?
Sometimes you need text that spans several lines, like a message, JSON, or SQL query.
Scala lets you write these with triple quotes, which preserve line breaks exactly as you type them.
val text = """Line one
Line two"""
println(text)Triple-Quoted Syntax
Wrap the text in three double quotes on each side: """...""".
Inside, you do not need to escape regular double quotes, which makes it ideal for text that contains quotes.
val json = """{"name": "Ada"}"""
println(json)All lessons in this course
- String Basics
- s, f and raw Interpolators
- Common String Methods
- Multiline Strings