golang bytes

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/youshijian99/article/details/85225341
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

猜你喜欢

转载自blog.csdn.net/youshijian99/article/details/85225341