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
+9.8k Golang : Identifying Golang HTTP client request
+4.8k Linux : How to set root password in Linux Mint
+5.9k Golang : Create new color from command line parameters
+11.4k Golang : Fuzzy string search or approximate string matching example
+7.9k Golang : HTTP Server Example
+9.6k Golang : Resumable upload to Google Drive(RESTful) example
+5.8k nginx : force all pages to be SSL
+5.3k Clean up Visual Studio For Mac installation failed disk full problem
+7.7k Golang Hello World Example
+5.6k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+18k Golang : Get command line arguments