分割/截取/拼接字符串
strs := strings.Split("this is a string", " ")
str1 := "this is a string"
strs := str1[0:5]
strs = strings.Join(strs,"_")
替换字符串
str := strings.Replace("this is a string", " ", "_", -1)
-1表示所有的空格都替换为下划线,如果是正数(n),就表示有n个空格替换为下划线
大小写转化
每个单词首字母大写
str := strings.toTitle("this is a string")
全部转大写
str := strings.toUpper("this is a string")
全部转小写
str := strings.toLower("THIS IS A STRING")
判断前后缀
fmt.Println(strings.HasPrefix("Gopher", "Go")) // true
fmt.Println(strings.HasPrefix("Gopher", "C")) // false
fmt.Println(strings.HasPrefix("Gopher", "")) // true
fmt.Println(strings.HasSuffix("Amigo", "go")) // true
fmt.Println(strings.HasSuffix("Amigo", "O")) // false
fmt.Println(strings.HasSuffix("Amigo", "Ami")) // false
fmt.Println(strings.HasSuffix("Amigo", "")) // true