0Pricing
Scala for Backend Engineering & Functional Programming · Lesson

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

  1. String Basics
  2. s, f and raw Interpolators
  3. Common String Methods
  4. Multiline Strings
← Back to Scala for Backend Engineering & Functional Programming