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字面理解就好。

文章来自:http://www.cnblogs.com/LVanswer/p/5592292.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3