func HasPrefix(s, prefix []byte) bool
判断s是否有前缀切片prefix。
package main
import (
"bytes"
"fmt"
)
func main() {
// 判断字符串是否包含"hel"
fmt.Println(bytes.HasPrefix([]byte("hello"), []byte("hel")))
fmt.Println(bytes.HasPrefix([]byte("heelo"), []byte("hel")))
}
运行结果:
true
false