目标c:如果有什么东西在其中 - 做点什么

时间:2010-08-09 19:12:09

标签: objective-c nsstring while-loop

我想这样做:

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

1 个答案:

答案 0 :(得分:4)

来自this stackoverflow帖子:

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

关键是要注意到这一点   rangeOfString:返回NSRange   struct,而documentation说   它返回结构   如果“干草堆”有,{NSNotFound, 0}   不包含“针”。

相关问题