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
+12.6k Golang : Arithmetic operation with numerical slices or arrays example
+25.9k Golang : Daemonizing a simple web server process example
+41.1k Golang : How to check if a string contains another sub-string?
+29.1k Golang : Get first few and last few characters from string
+11.8k Golang : Gorilla web tool kit secure cookie example
+15.7k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+20.2k Golang : Count number of digits from given integer value
+5.3k Javascript : Change page title to get viewer attention
+7k Golang : Find the shortest line of text example
+7.9k Golang : Get today's weekday name and calculate target day distance example