package main
import (
"fmt"
"strings"
)
func main() {
s := "hello world"
//是否包含
fmt.Println(strings.Contains(s, "hello"), strings.Contains(s, "?"))
//索引
fmt.Println(strings.Index(s, "o"))
ss := "1#2#345"
//分割字符串
splitedStr := strings.Split(ss, "#")
fmt.Println(splitedStr)
//合并字符串
fmt.Println(strings.Join(splitedStr, "#"))
//是否包含前缀,后缀
fmt.Println(strings.HasPrefix(s, "he"), strings.HasSuffix(s, "ld"))
}
输出:
转载于:https://blog.51cto.com/5660061/2361626