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
+25.4k Golang : convert rune to integer value
+24k Golang : Find biggest/largest number in array
+4.9k Google : Block or disable caching of your website content
+6k Golang : How to verify input is rune?
+37.6k Golang : Comparing date or timestamp
+6.5k PHP : Shuffle to display different content or advertisement
+7.6k Golang : Convert(cast) io.Reader type to string
+5.7k Unix/Linux : Get reboot history or check when was the last reboot date
+15.1k Golang : Save(pipe) HTTP response into a file
+12.5k Golang : Get absolute path to binary for os.Exec function with exec.LookPath
+14k Javascript : Prompt confirmation before exit