Standard library / bytes
bytes.FieldsFunc()
Splits on runs of runes accepted by f; predicate results must be consistent, and call order is unspecified. Returned subslices may alias input storage; copy before retaining independently. Expected stdout: '[a|b]\n'.
Formal Syntax & Structure
go syntaxgo
func FieldsFunc(s []byte, f func(rune) bool) [][]byteParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | []byte | Input text or sequence. |
| f | func(rune) bool | Predicate over decoded runes. |
Return Value
[][]byte
Splits on runs of runes accepted by f; predicate results must be consistent, and call order is unspecified. Returned subslices may alias input storage; copy before retaining independently.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt")
func main() { v := bytes.FieldsFunc([]byte("a,;b"), func(r rune) bool { return r == ',' || r == ';' }) fmt.Print("[") for i, x := range v { if i > 0 { fmt.Print("|") } fmt.Print(string(x)) } fmt.Println("]")}