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
+27.7k Golang : How to create new XML file ?
+5k AWS S3 : Prevent Hotlinking policy
+6k Golang : Trim everything onward after a word
+10.2k Golang : How to flush a channel before the end of program?
+10.6k Golang : convert(cast) float to string
+7.6k Golang : Accept any number of function arguments with three dots(...)
+10.4k Golang : Change date format to yyyy-mm-dd
+18.1k Golang : Determine if directory is empty with os.File.Readdir() function
+9.1k Golang : cannot assign type int to value (type uint8) in range error
+13.1k Golang : GUI with Qt and OpenCV to capture image from camera
+11.3k Golang : Exit, terminating or aborting a program
+14.8k Golang : Get sub string example