golang判斷字符串是否為空的方法:
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供桃源網(wǎng)站建設(shè)、桃源做網(wǎng)站、桃源網(wǎng)站設(shè)計、桃源網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、桃源企業(yè)網(wǎng)站模板建站服務(wù),十余年桃源做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
var s string if s=="" { }
或:
if len(s)==0{}
推薦使用第一種方法判斷字符串是否為空,就字符串是否為空這個語義而言,第一種語義更直接了當,應(yīng)該是更推薦的。
> 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判斷字符串是否為空的方法的詳細內(nèi)容,更多請關(guān)注創(chuàng)新互聯(lián)其它相關(guān)文章!