没有开始,结束Go的功能? [英] No startswith,endswith functions in Go?

查看:91
本文介绍了没有开始,结束Go的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方案

字符串包中包含 HasPrefix HasSuffix

 导入字符串

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

play.golang.org


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?

解决方案

The strings package contains HasPrefix and HasSuffix.

import "strings"

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

play.golang.org

这篇关于没有开始,结束Go的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆