问题描述:

This question already has an answer here:

  • How to detect if NSString is null?

    5 answers

网友答案:

You can do like this,

if ([yourString isEqual:[NSNull null]])
{
  //your code goes here
}

Hope this helps.

网友答案:

You can simply do like this,

    NSString * string = nil;
if (string!=nil &&  // not nil, means 0x0 object
    string.length>0 && // at leaset one character should exists
    [string isEqual:[NSNull null]]) { // to avoid 'null' in string

    // valid string
}
网友答案:

Use below

NSString *strResponseMsg = [responseFromJSON objectForKey:@"104"];   
if (!strResponseMsg)
{
    NSLog(@"login Invalid");
}
else
{
    NSLog(@"login success");
}
网友答案:

If you want to check the NSString whether it's nil or empty. You just need to do something like that:

if (strResponseMsg.length) {}

Because it will not go inside if the strResponseMsg is nil or empty. It will only go inside when strResponseMsg is not nil and no empty.

相关阅读:
Top