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

發佈了23 篇原創文章 · 獲贊 2 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章