Multi-line Strings

· 106 words · 1 minute read

This is an especially useful technique when working with large strings like SQL, HTML or XML within Go. Instead of using either the double quote (“) or single quote symbols (‘), instead use back-ticks to define the start and end of the string. You can then wrap it across lines. If you indent the string though, remember that the white space will count.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
package main

import "fmt"

func main() {

	message := `This is a 
Multi-line Text String
Because it uses the raw-string back ticks 
instead of quotes.
`

	fmt.Printf("%s", message)
}

Image of Author Edd Turtle

Author:  Edd Turtle

Edd is the Lead Developer at Hoowla, a prop-tech startup, where he spends much of his time working on production-ready Go and PHP code. He loves coding, but also enjoys cycling and camping in his spare time.

See something which isn't right? You can contribute to this page on GitHub or just let us know in the comments below - Thanks for reading!