strings 简单用法实例
package main
import (
	"fmt"
	"strings"
	"unicode"
)
func main() {
	var hello = "hello world"
	var abc = "a b c d e f g"
	// 在 string 里面找对应值返回 bool
	fmt.Println(strings.Contains(hello, "world"))
	// 按照空格切割,把空格切割掉
	fmt.Println(strings.Split(abc, " "))
	// 切割后返回子串,保留空格
	fmt.Println(strings.SplitAfter(abc, " "))
	// 替换
	fmt.Println(strings.ReplaceAll(hello, "hello", "nihao"))
	// 转换为大写
	fmt.Println(strings.ToUpper(hello))
	// 转换为小写
	fmt.Println(strings.ToLower(hello))
	// 大小写替换
	fmt.Println(strings.Map(toggleCase, hello))
}
func toggleCase(r rune) rune {
	if unicode.IsUpper(r) {
		return unicode.ToLower(r)
	} else if unicode.IsLower(r) {
		return unicode.ToUpper(r)
	}
	return r
}