Ad space (banner)
๐ŸฆSwift Lessons
Lesson 46 / 68

Multi-Line Strings (Triple Quotes)

In this lesson you will learn to write multi-line strings in Swift with triple quotes, so you can build readable messages. This is for anyone searching for "Swift multi-line string triple quotes".

Wrapping text in three double quotes lets you write a multi-line string with the line breaks included. It is handy for laying out an email body or a long explanation readably.

The sample code assembles a three-line message - greeting, thanks, and sign-off - inside triple quotes with \(name) embedded. Notice how the line breaks carry straight through into the string.

A common stumbling block for beginners is where the opening and closing triple quotes go. Because line breaks and indentation are preserved exactly, the wrong indentation can leave unintended whitespace in the string.

In real-world development it is valuable for laying out text such as HTML or JSON readably, and for building long messages such as an email body.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run Swift directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)