string Go 中没有开始和结束函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13244048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:40:52  来源:igfitidea点击:

No startswith,endswith functions in Go?

stringgo

提问by Sahas

Just curious to findout: why aren't there standard functions like startswith, endswith, etc as part of the standard libraries in the Go programming language?

只是好奇地发现:为什么 Go 编程语言中没有标准函数(如开始、结束等)作为标准库的一部分?

回答by Kyle Finley

The stringspackage contains HasPrefixand HasSuffix.

字符串包中包含HasPrefixHasSuffix

import "strings"

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

play.golang.org

play.golang.org