且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Objective C中测试字符串是否为空?

更新时间:2023-11-28 22:16:22

您可以检查 [字符串长度] == 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.