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