join two strings in go

In Go, you can join two strings using the plus (+) operator or the strings.Join() function.

Using the plus operator:

main.go
str1 := "Hello"
str2 := "world"
result := str1 + " " + str2 // Hello world
75 chars
4 lines

Using the strings.Join() function:

main.go
str1 := "Hello"
str2 := "world"
result := []string{str1, str2}
joinedResult := strings.Join(result, " ") // Hello world
120 chars
5 lines

gistlibby LogSnag