Standard library / bytes
bytes.Split()
Splits around every literal separator. Empty separator splits after UTF-8 sequences. Returned subslices may alias input storage; copy before retaining independently. Expected stdout: '[a||b]\n'.
Formal Syntax & Structure
go syntaxgo
func Split(s, sep []byte) [][]byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | []byte | Input text or sequence. |
| sep | []byte | Separator or search sequence. |
Return Value
[][]byte
Splits around every literal separator. Empty separator splits after UTF-8 sequences. Returned subslices may alias input storage; copy before retaining independently.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt")
func main() { v := bytes.Split([]byte("a,,b"), []byte(",")) fmt.Print("[") for i, x := range v { if i > 0 { fmt.Print("|") } fmt.Print(string(x)) } fmt.Println("]")}