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
+16.4k Golang : Multi threading or run two processes or more example
+8.1k Golang : Get curl -I or head data from URL example
+17.4k Golang : Display list of time zones with GMT
+6.9k Golang : Generate human readable password
+6.7k Javascript : Push notifications to browser with Push.js
+18.9k Golang : How to get time from unix nano example
+8.2k Golang : Write multiple lines or divide string into multiple lines
+7.8k Golang : How to join strings?
+6.6k Golang : Scanf function weird error in Windows
+28.2k Golang : How to create new XML file ?
+8.8k Golang : Validate IPv6 example
+5.2k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations