您好,登錄后才能下訂單哦!
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判斷字符串是否為空的方法的詳細內容,更多請關注億速云其它相關文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。