0
if ([pArray objectAtIndex:2]==@"ROOT")
{
    NSLog(@"YES");
}
else {
    NSLog(@"NO");
}

I am using this code but it's not working

5 Answers 5

1

You can use

- (BOOL)containsObject:(id)anObject; 

to check if the object is in the array. eg. [pArray containsObject:@"ROOT"];

if you need to check if particular element is equal to a string you can use.

[[pArray objectAtIndex:2] isEqualToString:@"ROOT"];

Both will return YES if matched.

Sign up to request clarification or add additional context in comments.

Comments

0

Use isEqualToString: method:

if ([[pArray objectAtIndex:2] isEqualToString:@"ROOT"]){
...
}

Comments

0

Assuming pArray contains strings... use the following...

if([[pArray objectAtIndex:2] isEqualToString:@"ROOT"])

Comments

0

You must use the isEqualToString method. You are attempting to compare two references in your statement.

if ([[pArray objectAtIndex:2] isEqualToString:@"ROOT"])

Comments

0
        if (([pArray objectAtIndex:2]  != (id)[NSNull null])&([[pArray objectAtIndex:2] isEqual:@"ROOT"])){
        NSLog(@"String in array is %@",[pArray objectAtIndex:2]);
    }
    else {
       if([pArray objectAtIndex:2]  == (id)[NSNull null]){
        NSLog(@"Your Object is Null");
       }
else{
   NSLog(@"Your Object does not match");
}   
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.