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
+10.9k Golang : Create Temporary File
+9.7k Golang : Format strings to SEO friendly URL example
+5.7k Unix/Linux : Get reboot history or check when was the last reboot date
+9.9k Golang : Check if user agent is a robot or crawler example
+5.2k PHP : Hide PHP version information from curl
+8.3k Golang : Convert word to its plural form example
+10.2k Golang : Embed secret text string into binary(executable) file
+6.8k Golang : Normalize email to prevent multiple signups example
+5.7k Javascript : How to replace HTML inside <div>?
+6.5k Golang : How to validate ISBN?
+12.7k Golang : Listen and Serve on sub domain example
+35.2k Golang : Smarter Error Handling with strings.Contains()