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
+18.8k Golang : convert int to string
+20k Golang : How to get time from unix nano example
+16.4k Golang : Loop each day of the current month example
+6.2k Golang : Build new URL for named or registered route with Gorilla webtoolkit example
+7k Golang : Normalize email to prevent multiple signups example
+21.9k Golang : How to reverse slice or array elements order
+12.5k Golang : Search and extract certain XML data example
+12.7k Golang : Exit, terminating or aborting a program
+3.8k Java : Random alphabets, alpha-numeric or numbers only string generator
+13.7k Golang : Strings comparison
+9.6k Mac OSX : Get a process/daemon status information