「TestSuper」という文字列があるとしましょう
「スーパー」を検出して、関数にYESを返すにはどうすればよいですか?
このようなもの:
return (([@"Test Super" rangeOfString:@"Super"]).location != NSNotFound);
rangeOfString:
結果の場所がに等しいかどうかを使用して確認しNSNotFound
ます。
[@"Test Super" rangeOfString:@"Super"].location != NSNotFound //YES
[@"Test Super" rangeOfString:@"Supper"].location != NSNotFound //NO
簡単なグーグルはこれを見つけます:http://objcolumnist.com/2009/04/12/does-a-nsstring-contain-a-substring/
NSRange textRange; textRange = [string rangeOfString:substring];
if(textRange.location != NSNotFound)
{
//Does contain the substring
}