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 : Embedded or data bundling example
+18.4k Golang : Send email with attachment
+5.9k Golang : Compound interest over time example
+10.8k Golang : Natural string sorting example
+5.7k Cash Flow : 50 days to pay your credit card debt
+12k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+6.2k Golang : How to search a list of records or data structures
+17.1k Golang : How to tell if a file is compressed either gzip or zip ?
+12.3k Golang : flag provided but not defined error
+9.5k Javascript : Read/parse JSON data from HTTP response
+40.8k Golang : How to check if a string contains another sub-string?
+19.4k Golang : Example for DSA(Digital Signature Algorithm) package functions