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
+19.8k Golang : GORM create record or insert new record into database example
+6.5k Golang : Gorrila set route name and get the current route name
+7k Golang : Variadic function arguments sanity check example
+8.2k Golang : How to generate Code 39 barcode?
+7.8k Golang : automatically figure out array length(size) with three dots
+7.2k Swift : Convert (cast) Character to Integer?
+8.7k Golang : Detect number of faces or vehicles in a photo
+4.6k Python : Print unicode escape characters and string
+9k Golang : Text file editor (accept input from screen and save to file)
+11.5k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+6.6k Golang : How to execute code at certain day, hour and minute?
+17.2k Golang : Padding data for encryption and un-padding data for decryption