package main
import (
"fmt"
"strings"
)
func testIndex() {
str := "http://www.baidu.com"
//查询字符出现的位置
index := strings.Index(str,"baidu")
fmt.Printf("baidu is index:%d\n",index)
index = strings.LastIndex(str,"com")
fmt.Printf("com is index:%d\n",index)
}
func main() {
testIndex()
}
输出:
baidu is index:11
com is index:17