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
+20.1k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+8.9k Golang : Edge detection with Sobel method
+9.8k Golang : How to determine a prime number?
+22.9k Golang : Call function from another package
+17.9k Golang : How to get own program name during runtime ?
+19.4k Golang : Convert PNG transparent background image to JPG or JPEG image
+10.8k Golang : Print UTF-8 fonts on image example
+4.5k Javascript : Shuffle or randomize array example
+6k Linux : How to fix Brother HL-1110 printing blank page problem
+10.3k Golang : Fuzzy string search or approximate string matching example
+4.7k List of Golang XML tutorials
+6.3k Golang : Check to see if *File is a file or directory