Reputation: 61
I have a logical condition that does not work. it would compare two characters, one taken from the xml and the other I insert myself.
to let you know I am attaching below the code
NSString *telefono = [NSString stringWithFormat:@"%@", [[arrayColonnine objectAtIndex:indexPath.row]objectForKey:@"telefono"]];
NSString *trimmedTelefono = [telefono stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
senzaTelefono = [[NSString alloc] initWithString:[trimmedTelefono stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if (telefono == @"NO")
if (trimmedTelefono == @"NO")
if (senzaTelefono == @"NO")
for each of the three strings if I do a log it print NO. but in none of the three cases the if works. how can I fix to make it work?
SOLUTION
the process is just this:
NSString *telefono = [NSString stringWithFormat:@"%@", [[arrayColonnine objectAtIndex:indexPath.row]objectForKey:@"telefono"]];
NSString *trimmedTelefono = [telefono stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([trimmedTelefono isEqualToString:@"NO"]) {
//do something...
}
Upvotes: 1
Views: 183
Reputation: 112857
You should use isEqualToString:
if ([telefono isEqualToString:@"NO"])
if (telefono == @"NO")
compares the objects being the same, not the contents being the same.
Upvotes: 3