Go: Multiline strings

Raw string literals

Raw string literals, delimited by back quotes, can contain line breaks.

str := `First line.
Second line.`
fmt.Println(str)
First line.
Second line.

Raw strings literals are interpreted literally and backslashes have no special meaning.

Interpreted string literals

To insert escape characters, use interpreted string literals delimited by double quotes.

str := "\tFirst line.\n" +
"Second line."
fmt.Println(str)
      First line.
Second line.

Comments

Be the first to comment!