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
+8.8k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+18.2k Golang : Logging with logrus
+15k Golang : Get all local users and print out their home directory, description and group id
+5.4k Javascript : How to refresh page with JQuery ?
+10.4k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+9.8k Golang : Get escape characters \u form from unicode characters
+20.8k Golang : How to force compile or remove object files first before rebuild?
+15k Golang : How to add color to string?
+9.5k PHP : Get coordinates latitude/longitude from string
+9.9k Golang : How to tokenize source code with text/scanner package?
+8.4k Golang : How to join strings?
+8.3k Android Studio : Import third-party library or package into Gradle Scripts