LastIndex
LastIndex 返回子串 substr 在字符串 s 中最后一次出现的位置,不存在则返回-1。
LastIndex
函数定义
func LastIndex(s, substr string) int
代码示例
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.Index("go gopher", "go")) //0
fmt.Println(strings.LastIndex("go gopher", "go")) //3
fmt.Println(strings.LastIndex("go gopher", "rodent")) //-1
}