GO語言"strings"包中"IndexRune"函數的用法及代碼示例。
用法:
func IndexRune(s string, r rune) int
IndexRune 返回 Unicode 代碼點 r 的第一個實例的索引,如果 s 中不存在符文,則返回 -1。如果 r 是 utf8 RuneError 它返回任何無效 UTF-8 字節序列的第一個實例。
例子:
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.IndexRune("chicken", 'k'))
fmt.Println(strings.IndexRune("chicken", 'd'))
}
輸出:
4 -1
相關用法
- GO IndexRune用法及代碼示例
- GO Index.Lookup用法及代碼示例
- GO IndexByte用法及代碼示例
- GO IndexFunc用法及代碼示例
- GO IndexAny用法及代碼示例
- 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用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 IndexRune。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。