strings.LastIndexByte() Golang中的函數返回原始字符串中給定字節的最後一個實例的索引。如果給定的字節在原始字符串中不可用,則此方法將返回-1。
用法:
func LastIndexByte(str string, b byte) int
在這裏,str是原始字符串,b是一個字節,我們要查找其最後一個索引值。
返回值:它返回整數。
範例1:
// Golang program to illustrate the
// strings.LastIndexByte() Function
package main
// importing fmt and strings
import (
"fmt"
"strings"
)
// calling main method
func main() {
// returns the last index of 'g' in string.
fmt.Println(strings.LastIndexByte("geeksforgeeks", 'g'))
// returns the last index of 'k' in string.
fmt.Println(strings.LastIndexByte("geekgeekgeek", 'k'))
}
輸出:
8 11
範例2:
// Golang program to illustrate the
// strings.LastIndexByte() Function
package main
// importing fmt and strings
import (
"fmt"
"strings"
)
// calling main method
func main() {
// performs case-insensitive search(returns -1).
fmt.Println(strings.LastIndexByte("GeeksForGeeks", 'g'))
// performs case-insensitive search(returns -1).
fmt.Println(strings.LastIndexByte("GeeKGeeKGeeK", 'k'))
}
輸出:
-1 -1
相關用法
- Golang math.Lgamma()用法及代碼示例
- Golang math.Float64bits()用法及代碼示例
- Golang atomic.AddInt64()用法及代碼示例
- Golang atomic.StoreInt64()用法及代碼示例
- Golang reflect.FieldByIndex()用法及代碼示例
- Golang string.Contains用法及代碼示例
- Golang bits.Sub()用法及代碼示例
- Golang io.PipeWriter.CloseWithError()用法及代碼示例
- Golang time.Round()用法及代碼示例
- Golang reflect.AppendSlice()用法及代碼示例
- Golang reflect.ChanOf()用法及代碼示例
- Golang flag.Bool()用法及代碼示例
- Golang time.Sleep()用法及代碼示例
- Golang time.Time.Year()用法及代碼示例
- Golang reflect.DeepEqual()用法及代碼示例
- Golang reflect.Indirect()用法及代碼示例
- Golang reflect.CanAddr()用法及代碼示例
- Golang reflect.CanInterface()用法及代碼示例
- Golang reflect.CanSet()用法及代碼示例
- Golang reflect.Cap()用法及代碼示例
注:本文由純淨天空篩選整理自PranchalKatiyar大神的英文原創作品 strings.LastIndexByte() Function in Golang With Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。