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
+16.8k Golang : When to use init() function?
+11.6k Golang : Get remaining text such as id or filename after last segment in URL path
+5.3k Fix fatal error: evacuation not done in time problem
+29.2k Golang : Get time.Duration in year, month, week or day
+7.6k Golang : Check from web if Go application is running or not
+18k Golang : Iterating Elements Over A List
+27.6k Golang : Connect to database (MySQL/MariaDB) server
+4.9k Golang : Pad file extension automagically
+16.9k Golang : Multi threading or run two processes or more example
+14k Golang : Parsing or breaking down URL
+11.8k Golang : calculate elapsed run time
+33.5k Golang : Proper way to set function argument default value