0Pricing
Swift Academy · Lesson

Multiline String Literals

Write readable multiline text with triple quotes.

Multiline String Literals

A multiline string literal spans several lines. It is delimited by three double-quote marks on their own lines, and the text in between keeps its line breaks.

let poem = """
Roses are red
Violets are blue
"""
print(poem)

Preserving Line Breaks

Each newline you type inside the literal becomes a newline in the resulting string, so formatting is preserved exactly.

let menu = """
Coffee
Tea
Water
"""
print(menu)

All lessons in this course

  1. Basic String Interpolation
  2. Formatting Numbers in Strings
  3. Multiline String Literals
  4. Custom String Interpolation
← Back to Swift Academy