What is the strings.Join method in Go?
The Join method of the strings module is used to condense strings.
Syntax
func Join(elems []string, sep string) string
Arguments
You need to give two arguments as input:
- An array of strings to use as elements.
- A separator that will be used when merging strings.
Return value
The method returns the merged string.
Code
In this example, we will create a slice of string and merge it with the character , (note the space).
See the code below.
package mainimport ("fmt""strings")func main() {s := []string{"Hello", "educative!"}fmt.Println(strings.Join(s, ", "))}