views:

31

answers:

1

I want to do this:

while(theString (does not have) @"this string" (in it)) {
do something
}
+4  A: 

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".

Stephen
+1 for the link to the docs
Merlyn Morgan-Graham
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