func test8() { // 常用方法 s := "hello world" fmt.Printf("len(s): %v\n", len(s)) s1 := "go" result := s + " " + s1 fmt.Printf("result: %v\n", result) result1 := fmt.Sprintf("%s, %s", s, s1) fmt.Printf("result1: %v\n", result1) fmt.Printf("strings.Split(s, \" \"): %v\n", strings.Split(s, " ")) fmt.Printf("strings.HasPrefix(\"hello\"): %v\n", strings.HasPrefix(s, "hello")) fmt.Printf("strings.HasSuffix(s, \"ld\"): %v\n", strings.HasSuffix(s, "ld")) fmt.Printf("strings.Index(s, \"l\"): %v\n", strings.Index(s, "l")) fmt.Printf("strings.LastIndex(s, \"l\"): %v\n", strings.LastIndex(s, "l")) fmt.Printf("strings.ToUpper(s): %v\n", strings.ToUpper(s)) fmt.Printf("strings.ToLower(s): %v\n", strings.ToLower(s)) } func main() { test8() } # 输出结果: len(s): 11 result: hello world go result1: hello world, go strings.Split(s, " "): [hello world] strings.HasPrefix("hello"): true strings.HasSuffix(s, "ld"): true strings.Index(s, "l"): 2 strings.LastIndex(s, "l"): 9 strings.ToUpper(s): HELLO WORLD strings.ToLower(s): hello world