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
+9.2k Golang : Extract or copy items from map based on value
+5.7k Golang : Detect variable or constant type
+12.3k Golang : Arithmetic operation with numerical slices or arrays example
+4.9k Python : Create Whois client or function example
+7.4k Golang : Command line ticker to show work in progress
+10k Golang : Embed secret text string into binary(executable) file
+6.9k Golang : Squaring elements in array
+8.2k Golang : Ackermann function example
+5.9k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+5.7k PHP : How to check if an array is empty ?
+5.3k PHP : Convert CSV to JSON with YQL example
+5.6k Unix/Linux : How to open tar.gz file ?