0

I want to do this:

while(theString (does not have) @"this string" (in it)) {
do something
}
objectiveccoder001
  • 2,929
  • 10
  • 43
  • 71

1 Answers1

4

From this stackoverflow post:

NSString *string = @"hello bla bla";
if ([string rangeOfString:@"bla"].location == NSNotFound) {
  NSLog(@"string does not contain bla");
} else {
  NSLog(@"string contains bla!");
}

The key is noticing that rangeOfString: returns an NSRange struct, and the documentation says that it returns the struct {NSNotFound, 0} if the "haystack" does not contain the "needle".

Community
  • 1
  • 1
Stephen
  • 5,659
  • 3
  • 33
  • 52
  • Thank you for the +1, but do please note that my post is a quote of another answer to an identical question - the original poster really deserves it more than me! – Stephen Aug 09 '10 at 19:27