脚本宝典收集整理的这篇文章主要介绍了golang判断字符串是否为空的方法,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
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知识请关注golang教程栏目。
以上就是golang判断字符串是否为空的方法的详细内容,更多请关注脚本宝典其它相关文章!
以上是脚本宝典为你收集整理的golang判断字符串是否为空的方法全部内容,希望文章能够帮你解决golang判断字符串是否为空的方法所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。