Ad space (banner)
๐ŸนGo Lessons
Lesson 46 / 68

Multi-Line Strings (Backquotes)

In this lesson you will learn to write multi-line strings in Go with backquotes (raw string literals), so you can build readable messages. This is for anyone searching for "Go multi-line string how to use".

Wrapping text in backquotes gives you a raw string literal: a multi-line string that keeps its line breaks and treats escapes literally. It is handy for long passages and SQL statements.

The sample code combines fmt.Sprintf with a backquoted multi-line string to assemble a greeting with a variable embedded. Notice how the line breaks carry straight through into the string.

A common stumbling block for beginners is knowing when to use backquotes rather than ordinary double quotes. Inside a backquoted string an escape sequence is treated as an ordinary run of characters, which needs care.

In real-world development raw string literals are valuable for anything symbol-heavy, such as SQL statements and JSON templates.

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

๐Ÿงช This site can't compile or run Go 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)