package main
import (
"fmt"
"strings"
)
func testHasPrefix() {
/**
判断前缀是否以xx开头
*/
str := "http://baidu.com"
if strings.HasPrefix(str,"http"){
fmt.Println("str is http url")
}else {
fmt.Println("str is not http url")
}
}
func testHasSuffix() {
//判断是否以xx结束
str := "http://baidu.com"
if strings.HasSuffix(str,"baidu.com"){
fmt.Println("str is baidu url")
}else {
fmt.Println("str is not baidu url")
}
}
func main() {
testHasPrefix()
testHasSuffix()
}
输出:
str is http url
str is baidu url