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) []stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | string | Input text or sequence. |
| f | func(rune) bool | Predicate 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("]")}