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
+32.6k Golang : convert(cast) bytes to string
+5.7k PHP : Shuffle to display different content or advertisement
+10.7k Golang : Clean formatting/indenting or pretty print JSON result
+17.3k Golang : Get path name to current directory or folder
+5k Golang : How to write backslash in string?
+50.3k Golang : How to get struct field and value by name
+19.5k Golang : Clean up null characters from input data
+12.7k Golang : How to pass map to html template and access the map's elements
+15.4k CodeIgniter/PHP : Create directory if does not exist example
+14.4k Golang : Loop each day of the current month example
+4.3k Responsive Google Adsense