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
+9.5k Golang : How to get username from email address
+7.4k Golang : alternative to os.Exit() function
+17.8k Golang : [json: cannot unmarshal object into Go value of type]
+29.3k Golang : missing Git command
+31.7k Golang : Example for ECDSA(Elliptic Curve Digital Signature Algorithm) package functions
+20.6k Swift : Convert (cast) Int to int32 or Uint32
+8.6k PHP : How to parse ElasticSearch JSON ?
+7k Golang : Pat multiplexer routing example
+17.7k Golang : Upload/Receive file progress indicator
+43.8k Golang : Get hardware information such as disk, memory and CPU usage
+21.8k Golang : GORM create record or insert new record into database example