ios NSNotFound的基本用法

来源:互联网 发布:帝国cms 调用相关内容 编辑:程序博客网 时间:2024/05/17 01:08

例一:

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

0 0
原创粉丝点击