Pooja
Pooja

Reputation: 2200

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.

Upvotes: 4

Views: 10432

Answers (4)

Krishnabhadra
Krishnabhadra

Reputation: 34265

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

Upvotes: 0

Chetan Bhalara
Chetan Bhalara

Reputation: 10344

Try this.

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

    {  
        [secondSplitArrayValue removeObjectAtIndex:i];  
    }  
} 

Upvotes: 0

visakh7
visakh7

Reputation: 26390

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

See if this helps

Upvotes: 0

Tovi7
Tovi7

Reputation: 2953

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.

Upvotes: 9

Related Questions