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

2017-09-12  本文已影响72人  朱晓晓的技术博客
NSString *tmpStr = @"asd苏打绿1234中介";  

NSRange range = [tmpStr rangeOfString:@"苏打绿"];  

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");  

  }
上一篇下一篇

猜你喜欢

热点阅读