0

Lets say I have a string "Test Super"

How would I detect "Super" and have the function return a YES?

3 Answers 3

4

Something like this:

return (([@"Test Super" rangeOfString:@"Super"]).location != NSNotFound);
Sign up to request clarification or add additional context in comments.

2 Comments

In case anyone is wondering, every single one of those parentheses is unnecessary. It's evidently just a style thing.
You mean unnecessary on Stack Overflow.
0

A quick google finds this: http://objcolumnist.com/2009/04/12/does-a-nsstring-contain-a-substring/

NSRange textRange; textRange =[string rangeOfString:substring];

if(textRange.location != NSNotFound)
{

//Does contain the substring
}

Comments

0

Use rangeOfString: and check if the result's location is equal to NSNotFound.

[@"Test Super" rangeOfString:@"Super"].location != NSNotFound //YES
[@"Test Super" rangeOfString:@"Supper"].location != NSNotFound //NO

2 Comments

This seems like the exact OPPOSITE of what OP wants. He wants not equal to NSNotFound.
Oh, I was just giving examples, not solving his precise need. But I will reverse the logic, to remove confusion.

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.