Golang : How to join strings?
Apart from using fmt.Sprint()
function to combine strings together. There is another way to concatenate string from different strings. One of them is to use strings.Join()
function.
For example :
package main
import (
"fmt"
"strings"
)
func main() {
str := []string{"join", "this", "string", "with another", "string\n"}
fmt.Printf(strings.Join(str, " "))
strUTF := []string{"join", "is", "UTF8 safe", "我", "join", "你\n"}
fmt.Printf(strings.Join(strUTF, " "))
}
Output :
join this string with another string
join is UTF8 safe 我 join 你
See also : Golang : concatenate(combine) strings
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
+6.2k Golang : Test input string for unicode example
+20.2k nginx: [emerg] unknown directive "passenger_enabled"
+11.6k Golang : Verify Linux user password again before executing a program example
+6.4k PHP : Shuffle to display different content or advertisement
+9.2k Golang : How to protect your source code from client, hosting company or hacker?
+8.8k Golang : GMail API create and send draft with simple upload attachment example
+11.5k CodeIgniter : Import Linkedin data
+8.1k Golang : Get final or effective URL with Request.URL example
+9.1k Golang : How to check if a string with spaces in between is numeric?
+7.8k Setting $GOPATH environment variable for Unix/Linux and Windows
+23.8k Golang : Call function from another package
+7.1k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream