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
+19.1k Golang : Close channel after ticker stopped example
+15.2k Golang : Get current time from the Internet time server(ntp) example
+15k Golang : Force download file example
+9.3k Golang : Eroding and dilating image with OpenCV example
+5.2k PHP : Fix Call to undefined function curl_init() error
+10.1k Golang : Select region of interest with mouse click and crop from image
+6.9k Golang : Example of custom handler for Gorilla's Path usage.
+11.8k Golang : Get month name from date example
+19.2k Golang : Measure http.Get() execution time
+18.5k Golang : Read input from console line
+9.1k Golang : Get all countries currencies code in JSON format