IndexFunc in Go

Posted by GoDoc
Public (Editable by Users)

IndexFunc returns the index into s of the first Unicode code point satisfying f(c), or -1 if none do.

Go
Edit
package main

import (
	"fmt"
	"strings"
	"unicode"
)

func main() {
	f := func(c rune) bool {
		return unicode.Is(unicode.Han, c)
	}
	fmt.Println(strings.IndexFunc("Hello, 世界", f))
	fmt.Println(strings.IndexFunc("Hello, world", f))
}