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
+4.8k JQuery : Calling a function inside Jquery(document) block
+16.9k Golang : Get input from keyboard
+11.8k Golang : Convert(cast) bigint to string
+17.7k Golang : Iterate linked list example
+6.6k Golang : Humanize and Titleize functions
+6.4k Golang : Combine slices of complex numbers and operation example
+20.9k Golang : For loop continue,break and range
+26.2k Golang : Get executable name behind process ID example
+10.8k Golang : Sieve of Eratosthenes algorithm
+20.4k Android Studio : AlertDialog and EditText to get user string input example
+10.2k Golang : Wait and sync.WaitGroup example
+5.8k Facebook : How to force facebook to scrape latest URL link data?