Golang Code

Multi-line Strings

· 92 words · 1 minute read #backtick #bytes #mutiline #printf #quotes #raw #string

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.

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.

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!