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
+55.3k Golang : Unmarshal JSON from http response
+6.1k Golang : How to write backslash in string?
+43.3k Golang : Convert []byte to image
+13.9k Golang : Get current time
+26.9k Golang : Force your program to run with root permissions
+6.9k Fix sudo yum hang problem with no output or error messages
+9.4k Golang : Find the length of big.Int variable example
+7.1k Golang : Get environment variable
+6.9k Nginx : Password protect a directory/folder
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+18.7k Unmarshal/Load CSV record into struct in Go