ios NSNotFound的基本用法

例一:

NSString *_string = [NSStringstrinWithFormat:@"123 456"];

NSRange _range = [_stringrangeOfString:@" "];

if (_range.location != NSNotFound){

     //有空格

}else{

     //没有空格

}

 

先查找空格的位置,然后查找到不到位置的即为-1.可以知道是否有空格

 

例二:

if ([videoURL rangeOfString:@"http://".location!=NSNotFound|| [videoURL rangeOFString:@"https://"].location != NSNotFound] )

{

      //网络请求格式正常

}else{

      //网络请求格式不是以http或者https开头的      

 

NSNotFound是用来判断这个字符串是否符合网络请求格式,即以http或https开头。NSNotFound字面理解就好。

posted @ 2016-06-16 22:05  SKT_answer  阅读(1249)  评论(0编辑  收藏  举报