如何在Objective C中测试字符串是否为空? [英] How do I test if a string is empty in Objective C?
本文介绍了如何在Objective C中测试字符串是否为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Objective C中测试 NSString
是否为空?
How do I test if an NSString
is empty in Objective C?
推荐答案
您可以检查 [字符串长度] == 0
。这将检查它是否是有效但空字符串(@)以及它是否为零,因为在nil上调用 length
也将返回0.。
You can check if [string length] == 0
. This will check if it's a valid but empty string (@"") as well as if it's nil, since calling length
on nil will also return 0.
这篇关于如何在Objective C中测试字符串是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文