Standard library / bytes

bytes.IndexFunc()

Returns the byte offset of the first rune satisfying f, or -1. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func IndexFunc(s []byte, f func(r rune) bool) int

Parameters & Attributes

NameTypeDescription
s[]byteInput text or sequence.
ffunc(r rune) boolPredicate over decoded runes.

Return Value

int

Returns the byte offset of the first rune satisfying f, or -1.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "unicode")
func main() {  fmt.Println(bytes.IndexFunc([]byte("é2"), unicode.IsDigit))}
Go Reference