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
+5.8k Golang : constant 20013 overflows byte error message
+7.8k Golang : Apply Histogram Equalization to color images
+4.8k Golang : Find change in a combination of coins example
+8.2k Golang : does not implement flag.Value (missing Set method)
+32.3k Golang : How to check if slice or array is empty?
+8.2k Golang : Web(Javascript) to server-side websocket example
+16.8k Golang : Iterating Elements Over A List
+11.9k Golang : List objects in AWS S3 bucket
+4.2k Javascript : Change page title to get viewer attention
+5k Linux/MacOSX : Search for files by filename and extension with find command
+21k Golang : untar or extract tar ball archive example
+24.4k Golang : How to write CSV data to file