字串包

  • strings.Contains

    fmt.Println(strings.Contains("foobar", "foo")) // true
    fmt.Println(strings.Contains("foobar", "baz")) // false
    
  • strings.HasPrefix

    fmt.Println(strings.HasPrefix("foobar", "foo")) // true
    fmt.Println(strings.HasPrefix("foobar", "baz")) // false
    
  • strings.HasSuffix

    fmt.Println(strings.HasSuffix("foobar", "bar")) // true
    fmt.Println(strings.HasSuffix("foobar", "baz")) // false
    
  • strings.Join

    ss := []string{"foo", "bar", "bar"}
    fmt.Println(strings.Join(ss, ", ")) // foo, bar, baz
    
  • strings.Replace

    fmt.Println(strings.Replace("foobar", "bar", "baz", 1)) // foobaz
    
  • strings.Split

    s := "foo, bar, bar"
    fmt.Println(strings.Split(s, ", ")) // [foo bar baz]
    
  • strings.ToLower

    fmt.Println(strings.ToLower("FOOBAR")) // foobar
    
  • strings.ToUpper

    fmt.Println(strings.ToUpper("foobar")) // FOOBAR
    
  • strings.TrimSpace

    fmt.Println(strings.TrimSpace("  foobar  ")) // foobar
    

更多: https//golang.org/pkg/strings/