如果你想知道字符串内的某处是否包含其他字符串,使用rangeOfString: 方法
-(NSRange)rangeOfString :(NSString *)aString;
1 NSString *num = @"sdhfdsjkljg"; 2 3 NSRange a =[num rangeOfString:@"hf"]; 4 NSLog(@"%@",NSStringFromRange(a)); 5 //输出{2, 2}
NSStringFromRange :Returns a string representation of a range
NSString *str = @"hello world ,I'm coming"; NSRange range = [str rangeOfString:@"world"]; NSLog(@"location:%ld,length:%ld",range.location,range.length);