Golang : Write multiple lines or divide string into multiple lines
Problem :
You have a long string and you need to divide the string into multiple lines. How to do that in Golang?
Solutions :
Solution 0 :
"line 1" +
"line 2" +
"line 3"
Solution 1 ( for web):
func SayHelloWorld(w http.ResponseWriter, r *http.Request) {
html := "Hello"
html = html + " World"
w.Write([]byte(html))
}
Solution 2:
"""line 1
line 2
line 3"""
Solution 3:
`line 1
line 2
line 3`
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+4.2k Golang : Pad file extension automagically
+3.7k Linux : sudo yum updates not working
+14.9k Golang : Read integer from file into array
+8.4k Facebook : Getting the friends list with PHP return JSON format
+11.4k Elastic Search : Return all records (higher than default 10)
+11.9k Golang : Increment string example
+27.5k Golang : Saving(serializing) and reading file with GOB
+2.2k Golang : Switch Redis database redis.NewClient
+7.9k Golang : Intercept and compare HTTP response code example
+9.1k Golang : How to tokenize source code with text/scanner package?
+5.8k Fix sudo yum hang problem with no output or error messages
+8.1k Golang : Timeout example