Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NOT(!) in objective c

for (int i=0 ; i<=[secondSplitArrayValue count]; i++)   
{    
  if (![[secondSplitArrayValue objectAtIndex:i] isEqualToString:@"NULL"] ||  
  ![[splitArrayValue objectAtIndex:i] isEqualToString:@"Error"]   
    {  
        [secondSplitArrayValue removeObjectAtIndex:i];  
    }  
}  

I am trying to remove value of array at particular index where string is NOT EQUAL (!=) to NULL or Error. But in debugging time object is removed where NULL and Error present but I want to remove object where Null and Error not present.

like image 994
Pooja Avatar asked Jan 19 '23 22:01

Pooja


1 Answers

You're probably looking for this I think:

for (int i=0 ; i<=[secondSplitArrayValue count]; i++)   
{    
  if (!([[secondSplitArrayValue objectAtIndex:i] isEqualToString:@"NULL"] ||  
  [[splitArrayValue objectAtIndex:i] isEqualToString:@"Error"])   
    {  
        [secondSplitArrayValue removeObjectAtIndex:i];  
    }  
}  

This way you inverse the boolean operation only after you have completed the check for both cases, and the OR operation of both of the resulting checks.

like image 60
Tovi7 Avatar answered Jan 28 '23 12:01

Tovi7