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
+33.3k Golang : All update packages with go get command
+5.1k Golang : How to deal with configuration data?
+27.1k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+19.7k Golang : How to get own program name during runtime ?
+4.5k MariaDB/MySQL : Form select statement or search query with Chinese characters
+21.7k Golang : Convert seconds to minutes and remainder seconds
+10.8k Golang : Read until certain character to break for loop
+9.4k Golang : interface - when and where to use examples
+30.1k Golang : Generate random string
+19.8k Golang : Check if os.Stdin input data is piped or from terminal
+6.7k Golang : constant 20013 overflows byte error message