Standard library / strings

strings.FieldsFunc()

Splits on runs of runes accepted by f; predicate results must be consistent, and call order is unspecified. Expected stdout: '[a|b]\n'.

Formal Syntax & Structure

go syntaxgo
func FieldsFunc(s string, f func(rune) bool) []string

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
ffunc(rune) boolPredicate over decoded runes.

Return Value

[]string

Splits on runs of runes accepted by f; predicate results must be consistent, and call order is unspecified.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings")
func main() {  v := strings.FieldsFunc("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("]")}
Go Reference