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
+22.5k Golang : How to read JPG(JPEG), GIF and PNG files ?
+7.1k Golang : Validate credit card example
+11.2k Golang : Roll the dice example
+28.3k Golang : Connect to database (MySQL/MariaDB) server
+8.8k Golang : Executing and evaluating nested loop in html template
+15.5k Golang : invalid character ',' looking for beginning of value
+7.2k Golang : Get environment variable
+8.9k Golang : Sort lines of text example
+7.1k Web : How to see your website from different countries?
+10.1k Golang : Test a slice of integers for odd and even numbers
+20k Golang : How to get time from unix nano example
+6.2k Golang : Create new color from command line parameters