Standard library / strings

strings.Split()

Splits around every literal separator. Empty separator splits after UTF-8 sequences. Expected stdout: '[a||b]\n'.

Formal Syntax & Structure

go syntaxgo
func Split(s, sep string) []string

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
sepstringSeparator or search sequence.

Return Value

[]string

Splits around every literal separator. Empty separator splits after UTF-8 sequences.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  v := strings.Split("a,,b", ",")  fmt.Print("[")  for i, x := range v {    if i > 0 {      fmt.Print("|")    }    fmt.Print(string(x))  }  fmt.Println("]")}
Go Reference