GO語言"bytes"包中"IndexFunc"函數的用法及代碼示例。
用法:
func IndexFunc(s []byte, f func(r rune) bool) int
IndexFunc 將 s 解釋為 UTF-8 編碼的代碼點序列。它返回滿足 f(c) 的第一個 Unicode 代碼點的 s 中的字節索引,如果不滿足,則返回 -1。
例子:
package main
import (
"bytes"
"fmt"
"unicode"
)
func main() {
f := func(c rune) bool {
return unicode.Is(unicode.Han, c)
}
fmt.Println(bytes.IndexFunc([]byte("Hello, 世界"), f))
fmt.Println(bytes.IndexFunc([]byte("Hello, world"), f))
}
輸出:
7 -1
相關用法
- GO Index.Lookup用法及代碼示例
- GO IndexByte用法及代碼示例
- GO IndexAny用法及代碼示例
- GO IndexRune用法及代碼示例
- GO Index用法及代碼示例
- GO Indent用法及代碼示例
- GO Int.Scan用法及代碼示例
- GO Ints用法及代碼示例
- GO Intn用法及代碼示例
- GO Info用法及代碼示例
- GO Int.SetString用法及代碼示例
- GO Inspect用法及代碼示例
- GO IntsAreSorted用法及代碼示例
- GO Itoa用法及代碼示例
- GO IP.IsPrivate用法及代碼示例
- GO IsDigit用法及代碼示例
- GO IP.Equal用法及代碼示例
- GO IsAbs用法及代碼示例
- GO IP.IsLinkLocalMulticast用法及代碼示例
- GO IsGraphic用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 IndexFunc。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。