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.5k Golang : How to search a list of records or data structures
+8.3k Golang : Qt splash screen with delay example
+9.2k Golang : Handle sub domain with Gin
+5.1k Golang : Calculate a pip value and distance to target profit example
+35.4k Golang : Strip slashes from string example
+12.9k Golang : Listen and Serve on sub domain example
+9.2k Golang : Simple histogram example
+24.7k Golang : Time slice or date sort and reverse sort example
+10.9k Golang : Command line file upload program to server example
+17.4k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+46.4k Golang : Read tab delimited file with encoding/csv package
+10.9k PHP : Convert(cast) bigInt to string