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
+48.1k Golang : How to convert JSON string to map and slice
+29.3k Golang : JQuery AJAX post data to server and send data back to client example
+8.7k Golang : Combine slices but preserve order example
+5.8k Cash Flow : 50 days to pay your credit card debt
+20.8k Golang : Convert date string to variants of time.Time type examples
+16.8k Golang : Get own process identifier
+16.5k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+7.1k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+23k Golang : simulate tail -f or read last line from log file example
+12.6k Golang : Remove or trim extra comma from CSV
+6.9k Golang : Levenshtein distance example
+15.8k Golang : Get digits from integer before and after given position example