0

I am using this Code snippet to search for an String inside another String. It works fine for the first if, but then after the second if it only returns YES (true) if I search for both Words (Word from first if, the Word I want to search now)

works if hypothesis contains : "OPEN TWITTER" not if it is "PLEASE OPEN TWITTER" p.e.

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://"]];
    }
}

I want it to work also if there are any other Words in the String, I just want to it to hit on the Keywords somewhere in the String and then return YES (to determine that 'hypothesis' contains the words and then do the action)

5
  • 1
    try using else if, using a lot of if statements causes the program to go wack-o with the logic Commented May 6, 2013 at 19:11
  • 1
    What's the result of 100 == !10? What's the result of 100 != 10? Commented May 6, 2013 at 19:12
  • @Fogmeister did the exact same this sec Commented May 6, 2013 at 19:13
  • Oh gosh what a dumb thing^^ Thanks so much.. Commented May 6, 2013 at 19:16
  • This question should be removed because it is predicated on a typo and will have no usefulness for future searchers. Commented Oct 11, 2013 at 5:26

1 Answer 1

3
== !NSNotFound

should be changed to

!= NSNotFound
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.