搜索子字符串

要搜索 String 是否包含子字符串,请执行以下操作:

NSString *myString = @"This is for checking substrings";
NSString *subString = @"checking"; 

BOOL doesContainSubstring = [myString containsString:subString];  // YES

如果定位到 iOS 7 或 OS X 10.9(或更早版本):

BOOL doesContainSubstring = ([myString rangeOfString:subString].location != NSNotFound);  // YES