golang判断字符串是否为空的方法
互联网
19-12-26

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 writelen(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 compilelen(s) == 0 and s == "" into the same, efficient code.Right now 6g etc do compile s == "" into a function callwhile len(s) == 0 is not, but that's been on my to-do list to fix.>Make the code clear.>>Russ
更多golang知识请关注golang教程栏目。
以上就是golang判断字符串是否为空的方法的详细内容,更多内容请关注技术你好其它相关文章!
免责声明:
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场
1.资讯内容不构成投资建议,投资者应独立决策并自行承担风险
2.本文版权归属原作所有,仅代表作者本人观点,不代表本站的观点或立场