IndexFunc
IndexFunc 返回字符串 s 中第一个满足函数f(rune)的位置i(该处的utf-8码值r满足f(r)==true),不存在则返回-1。
IndexFunc
函数定义
func IndexFunc(s string, f func(rune) bool) int
代码示例
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)) //7
fmt.Println(strings.IndexFunc("Hello, world", f)) //-1
}