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
+19.3k PHP : Convert(cast) int to double/float
+8.7k Golang : Sort and reverse sort a slice of floats
+4.4k Golang : If else example and common mistake
+5k Fix ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)
+7.8k Golang : Handle sub domain with Gin
+5.6k Golang : How to setup a disk space used monitoring service with Telegram bot
+3.8k JavaScript : Rounding number to decimal formats to display currency
+6k Golang : Null and nil value
+16.8k Golang : Check if a directory exist or not
+4.5k Golang : Intercept, inject and replay HTTP traffics from web server
+11.4k Golang : "https://" not allowed in import path