2013-05-06 5 views
0

J'utilise cet extrait de code pour rechercher une chaîne dans une autre chaîne. Cela fonctionne bien pour le premier si, mais après le second si il ne renvoie que YES (vrai) si je recherche les deux mots (Word from first if, le mot que je veux rechercher maintenant)Rechercher une chaîne spécifique dans une autre chaîne

fonctionne si l'hypothèse contient : "OPEN TWITTER" pas si c'est "PLEASE OPEN TWITTER" pe

if ([hypothesis rangeOfString:@"OPEN"].location == !NSNotFound) { 
    NSLog(@"hypothesis contains OPEN"); 
    if ([hypothesis rangeOfString:@"OPEN TWITTER"].location == !NSNotFound) { 
     [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"twitter://"]]; 
    } 
    if ([hypothesis rangeOfString:@"OPEN FACEBOOK"].location == !NSNotFound) { 
     [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"fb://"]]; 
    } 
} 

Je veux que cela fonctionne aussi s'il y a d'autres mots dans la chaîne, je veux juste pour frapper sur les mots clés quelque part dans la chaîne, puis revenir OUI (pour déterminer que « hypothèse » contient les mots, puis faire l'action)

+1

essayer d'utiliser d'autre si, en utilisant beaucoup d'instructions if pidof aller Wack-o avec la logique – user2277872

+1

Quel est le résultat o f '100 ==! 10'? Quel est le résultat de '100! = 10'? –

+0

@Fogmeister a fait exactement la même chose ce sec – Maurice

Répondre

3
== !NSNotFound 

devrait être remplacé

!= NSNotFound 
Questions connexes