Does Go have anything similar to Python's multiline strings:
"""line 1 line 2 line 3"""
If not, what is the preferred way of writing strings spanning multiple lines?
Three single quotes, three double quotes, brackets, and backslash can be used to create multiline strings. Whereas the user needs to mention the use of spaces between the strings.
A string in memory can contain as many '\n' characters as you like. The string "foo\nbar\n" , when written to a text file, will create two lines, "foo" and "bar" .
Raw StringsThey can span multiple lines without concatenation and they don't use escaped sequences. You can use backslashes or double quotes directly.
According to the language specification you can use a raw string literal, where the string is delimited by backticks instead of double quotes.
`line 1 line 2 line 3`
You can write:
"line 1" + "line 2" + "line 3"
which is the same as:
"line 1line 2line 3"
Unlike using back ticks, it will preserve escape characters. Note that the "+" must be on the 'leading' line - for instance, the following will generate an error:
"line 1" +"line 2"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With