Checking for string contents? string Length Vs Empty String

前端 未结 13 910
野趣味
野趣味 2020-12-17 10:14

Which is more efficient for the compiler and the best practice for checking whether a string is blank?

  1. Checking whether the length of the string == 0
13条回答
  •  轮回少年
    2020-12-17 10:35

    Again, without knowing the language, it's impossible to tell.

    However, I recommend that you choose the technique that makes the most sense to the maintenance programmer that follows and will have to maintain your work.

    I'd recommend writing a function that explicitly does what you want, such as

    #define IS_EMPTY(s) ((s)[0]==0)
    

    or comparable. Now there's no doubt at is you're checking.

提交回复
热议问题