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
+23.9k Golang : How to validate URL the right way
+21k Curl usage examples with Golang
+6.1k Golang : Break string into a slice of characters example
+17.1k Golang : Get future or past hours, minutes or seconds
+34.1k Golang : Smarter Error Handling with strings.Contains()
+13.1k Golang : Read from buffered reader until specific number of bytes
+11.8k Golang : Perform sanity checks on filename example
+21.2k Golang : GORM create record or insert new record into database example
+7.3k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+13.6k Golang : convert(cast) string to float value
+6.4k Golang : Warp text string by number of characters or runes example
+7.5k Golang : Trim everything onward after a word