go语言怎么判断字符串是否为空-创新互联

golang判断字符串是否为空的方法:

成都创新互联专注于王益网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供王益营销型网站建设,王益网站制作、王益网页设计、王益网站官网定制、小程序制作服务,打造王益网络公司原创品牌,更为您提供王益网站排名全网营销落地服务。
var s string
if s=="" {
    
}

或:

if len(s)==0{}

推荐使用第一种方法判断字符串是否为空,就字符串是否为空这个语义而言,第一种语义更直接了当,应该是更推荐的。

> The one that makes the code clear.
If I'm about to look at element x I typically write
len(s) > x, even for x == 0, but if I care about
"is it this specific string" I tend to write s == "".
>
>It's reasonable to assume that a mature compiler will compile
len(s) == 0 and s == "" into the same, efficient code.
Right now 6g etc do compile s == "" into a function call
while len(s) == 0 is not, but that's been on my to-do list to fix.

>Make the code clear.
>
>Russ

以上就是golang判断字符串是否为空的方法的详细内容,更多请关注创新互联成都网站设计公司其它相关文章!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章标题:go语言怎么判断字符串是否为空-创新互联
文章分享:http://myzitong.com/article/dchjog.html