The Split() method in Golang (defined in the strings library) breaks a string down into a list of substrings using a specified separator. The method returns the substrings in the form of a slice.
This is how the function is defined in Golang:
func Split(str, sep string) []string
str is the string to be split.sep. If an empty string is provided as the separator, then the string is split at every character.The following code snippet shows how the Split method is used:
package mainimport "fmt"import "strings" // Needed to use Splitfunc main() {str := "hi, this is, educative"split := strings.Split(str, ",")fmt.Println(split)fmt.Println("The length of the slice is:", len(split))}
Free Resources