views:

82

answers:

1

I have a long string that has a running list of all the "words entered" in the text box. I want to be able to check the long string against a one word string to see if the long string contains the word in the short string.

Any ideas?

I've tried this and a few other things, where newString is the long string and currentTextrightnow is the short string.

textRange =[newString rangeOfString:currentTextrightnow];
NSLog(@"currenttextright now is %@", currentTextrightnow);
if(textRange.location != NSNotFound)

{

    NSLog(@"Does contatin the substring");

}
+4  A: 

I had the same problem as you did. You are actually doing it right (if textRange is of type NSRange) but the problem is NSNotFound doesn't work as expected (might be a bug). Instead you can do

if (range.length > 0) {
    //it found it
} else {
    // it didn't find it
}

Hope that helps.

Rudiger
THANK YOU!!!! This fixed it
Bdennis317
Why post that it worked and not mark it correct? Seriously?
Rudiger