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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。