[string length]
works, but it will return zero if it is also zero. If this is acceptable to you, it is easier.
btw nested ternary operators are fine in your own home, but if you are writing code for sharing, it might be better to decompose it so that it is obvious.
In response to the comments, how would I do this:
if((([a length] == 0) && ([b length] == 0)) || ([a isEqualToString:b])) { // they are equal }
If one sentence is executed, the lines are equal. The second catches any non-zero lines that are actually equal, including @"" == @"" . The first catches a and b both nil and one nil and one @"" . At first I wrote first as ((a == nil) && (b == nil)) , but you said that @"" should be zero.
Adam eberbach
source share