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