Standard library / strings

strings.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 string, f func(rune) bool) int

Parameters & Attributes

NameTypeDescription
sstringInput text or sequence.
ffunc(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 (  "fmt"  "strings"  "unicode")
func main() {  fmt.Println(strings.IndexFunc("é2", unicode.IsDigit))}
Go Reference