Ad space (banner)
๐ŸŽฏKotlin Lessons
Lesson 46 / 68

Multi-Line Strings (Triple Quotes)

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

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, then removes the extra indentation from the surrounding code with .trimIndent().

A common stumbling block for beginners is forgetting .trimIndent(). A triple-quoted string keeps the code's indentation as well, so without it you get unwanted whitespace in the output.

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 Kotlin 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)