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
+13.8k Golang : How to determine if user agent is a mobile device example
+6.1k Golang : Totalize or add-up an array or slice example
+9.1k Golang : Copy map(hash table) example
+29.8k Golang : Remove characters from string example
+10.8k Golang : Post data with url.Values{}
+10.4k Golang : Create Temporary File
+17k Golang : Parse date string and convert to dd-mm-yyyy format
+7.7k Golang : Emulate NumPy way of creating matrix example
+13.3k Golang : How to check if a file is hidden?
+22.2k Golang : Strings to lowercase and uppercase example
+12.8k Facebook PHP getUser() returns 0
+13.6k Golang : How to convert a number to words