iOS搜索指定字符在字符串中的位置

NSString *tmpStr = @"asd341234aaaaccd";

NSRange range;

range = [tmpStr rangeOfString:@"ccd"];

if (range.location != NSNotFound) {

  NSLog(@"found at location = %lu, length = %lu",(unsigned long)range.location,(unsigned long)range.length);  

NSString *ok = [tmpStr substringFromIndex:range.location];

  NSLog(@"%@",ok);  

}else{

  NSLog(@"Not Found");  

}

你可能感兴趣的:(iOS搜索指定字符在字符串中的位置)