Split, SplitN, SplitAfter
Split drops the separator; SplitAfter keeps it. SplitN caps the number of pieces.
strings.Split("a,b,c", ",") // ["a" "b" "c"]
strings.SplitN("a,b,c", ",", 2) // ["a" "b,c"]
strings.SplitAfter("a,b,c", ",") // ["a," "b," "c"]
strings.Fields(" hello world ") // ["hello" "world"] — any whitespace
Join
strings.Join([]string{"a", "b", "c"}, ", ") // "a, b, c"
Cut — idiomatic single split
Cut is the modern (1.18+) way to split on a separator once. Cleaner than SplitN(2).
k, v, ok := strings.Cut("name=ada", "=")
fmt.Println(k, v, ok)
k, v, ok = strings.Cut("bare", "=")
fmt.Println(k, v, ok) // "bare", "", false
Output
name ada true
bare false
CutPrefix / CutSuffix (1.20+)
s, ok := strings.CutPrefix("go-mod", "go-") // "mod", true
s, ok = strings.CutSuffix("app.log", ".log") // "app", true