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
+8.1k Golang : Generate Codabar
+5.8k Golang : Get expvar(export variables) to work with multiplexer
+7.9k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+6.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+4.3k Golang *File points to a file or directory ?
+12.7k Golang : How to pass map to html template and access the map's elements
+7.8k Golang : Heap sort example
+6.1k Web : How to see your website from different countries?
+16.1k Golang : Qt image viewer example
+32.9k Golang : Integer is between a range
+15.4k CodeIgniter/PHP : Create directory if does not exist example
+8.6k Golang : How to check if a website is served via HTTPS