与TrimLeft的区别:strings.TrimLeft() 函数不仅仅删除一样的前缀,若剩下的字符串中有跟前缀一样的字符,也会删掉。
func TrimPrefix(s, prefix string) string
package main
import (
"fmt"
"strings"
)
func main() {
var s = "¡¡¡Hello, Gophers!!!"
s = strings.TrimPrefix(s, "¡¡¡Hello, ")
fmt.Println(s)
s = strings.TrimPrefix(s, "¡¡¡Howdy, ")
fmt.Println(s)
s = strings.TrimLeft(s, "¡¡¡HowdyGs, ")
fmt.Println(s)
}
// Output:
// Gophers!!!
// Gophers!!!
// phers!!!