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
+6.4k Golang : Skip or discard items of non-interest when iterating example
+19.8k Golang : Convert seconds to human readable time format example
+6.6k Get Facebook friends working in same company
+8.1k Useful methods to access blocked websites
+40.7k Golang : How to check if a string contains another sub-string?
+5k PHP : See installed compiled-in-modules
+7.9k Android Studio : Rating bar example
+35.8k Golang : How to split or chunking a file to smaller pieces?
+11.8k Golang : Pagination with go-paginator configuration example
+40.8k Golang : How to count duplicate items in slice/array?
+9.1k Golang : Timeout example