没有startwith,结束Go中的功能?

Sah*_*has 139 string go

只是好奇地发现:为什么没有像startwith,endswith等标准函数作为Go编程语言中标准库的一部分?

Kyl*_*ley 254

字符串包中包含HasPrefixHasSuffix.

import "strings"

startsWith := strings.HasPrefix("prefix", "pre") // true
endsWith := strings.HasSuffix("suffix", "fix") // true
Run Code Online (Sandbox Code Playgroud)

play.golang.org