0

假设我有一个字符串“Test Super”

我将如何检测“超级”并让函数返回“是”?

4

3 回答 3

4

像这样的东西:

return (([@"Test Super" rangeOfString:@"Super"]).location != NSNotFound);
于 2012-09-20T22:41:24.047 回答
0

使用rangeOfString:并检查结果的位置是否等于NSNotFound.

[@"Test Super" rangeOfString:@"Super"].location != NSNotFound //YES
[@"Test Super" rangeOfString:@"Supper"].location != NSNotFound //NO
于 2012-09-20T22:39:44.440 回答
0

一个快速的谷歌发现这个: http: //objcolumnist.com/2009/04/12/does-a-nsstring-contain-a-substring/

NSRange 文本范围;textRange =[字符串 rangeOfString:substring];

if(textRange.location != NSNotFound)
{

//Does contain the substring
}
于 2012-09-20T22:41:37.027 回答