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