Go中没有startswith、endswith函数吗?

2024-03-26

只是好奇地想知道:为什么 Go 编程语言中的标准库中没有像startswith、endswith 等标准函数?


The strings http://golang.org/pkg/strings包装包含有前缀 http://golang.org/pkg/strings/#HasPrefix and 有后缀 http://golang.org/pkg/strings/#HasSuffix.

import "strings"

startsWith := strings.HasPrefix("prefix", "pre") // true
endsWith := strings.HasSuffix("suffix", "fix") // true

play.golang.org http://play.golang.org/p/c8TQuCk-U9

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Go中没有startswith、endswith函数吗? 的相关文章

随机推荐