mercredi 27 mai 2015

else if condition is not working

I need to check in two of string, if those string contains any particular string or not e.g i need to search if my both of strings contains "Australia" or not. If not then append "Australia" to the string in which "Australia" is not present, for this i am writing this

 NSString *startLocationAddress = @"Any address for start location";
 NSString *endLocationAddress = @"Any address for end location";

 if ([startLocationAddress rangeOfString:@"Australia"].location == NSNotFound)
 {
     NSLog(@"string does not contain Australia");
     startLocationAddress = [startLocationAddress stringByAppendingString:@",Australia"];
 }
 else if ([endLocationAddress rangeOfString:@"Australia"].location == NSNotFound)
 {
     NSLog(@"string does not contain Australia");
     endLocationAddress =[endLocationAddress stringByAppendingString:@",Australia"];
 }
 else {
     NSLog(@"string contain Australia");
 }

As my both of strings does not contains "Australia". First if condition is working fine and it append "Australia" to the string but second else if condition is not working. Although i applied the different approach to solve my problem, but i need to know what is wrong in this code. Any help would be highly appreciable. Thanks.

Aucun commentaire:

Enregistrer un commentaire