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
+7.3k Golang : Not able to grep log.Println() output
+18.8k Golang : How to make function callback or pass value from function as parameter?
+15.8k Golang : Get digits from integer before and after given position example
+12.3k Golang : Get month name from date example
+7.3k Golang : Example of custom handler for Gorilla's Path usage.
+8.5k Golang : How to check variable or object type during runtime?
+9.6k Golang : How to extract video or image files from html source code
+29.8k Golang : Get and Set User-Agent examples
+23.1k Golang : Print out struct values in string format
+22.9k Golang : Calculate time different
+17k Golang : Capture stdout of a child process and act according to the result
+26.4k Golang : Get executable name behind process ID example