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
+11.4k Golang : Display a text file line by line with line number example
+16.4k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+5.6k Get website traffic ranking with Similar Web or Alexa
+4.9k Golang : Constant and variable names in native language
+7.2k Golang : Calculate how many weeks left to go in a given year
+9.6k Golang : Detect number of active displays and the display's resolution
+7k Nginx : How to block user agent ?
+14.2k Golang : Recombine chunked files example
+6k Golang : Debug with Godebug
+8.9k Golang : Build and compile multiple source files
+9.7k Golang : Get current, epoch time and display by year, month and day
+9.4k Golang : How to extract video or image files from html source code