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
+17.3k Google Chrome : Your connection to website is encrypted with obsolete cryptography
+4.7k Mac OSX : Get disk partitions' size, type and name
+21.9k SSL : How to check if current certificate is sha1 or sha2
+4.8k Chrome : How to block socketloop.com links in Google SERP?
+4.8k Unix/Linux : How to pipe/save output of a command to file?
+41.5k Golang : Convert string to array/slice
+88.4k Golang : How to convert character to ASCII and back
+9.4k Golang : How to get username from email address
+5.5k How to check with curl if my website or the asset is gzipped ?
+7.5k Golang : Accessing dataframe-go element by row, column and name example
+5.7k Swift : Get substring with rangeOfString() function example
+13.6k Golang : How to get year, month and day?