美文网首页
iOS开发之搜索指定字符在字符串中的位置

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

作者: 朱晓晓的技术博客 | 来源:发表于2017-09-12 15:13 被阅读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");  

  }

相关文章

网友评论

      本文标题:iOS开发之搜索指定字符在字符串中的位置

      本文链接:https://www.haomeiwen.com/subject/gqmcsxtx.html