#import <Foundation/Foundation.h>
void test(){ NSString *url1 = @"https://www.xxxxxx.com"; //1.检查前缀 BOOL isYes = [url1 hasPrefix:@"https://"]; if (isYes) { NSLog(@"这是个合法网址"); }
//2.检查后缀 url1 = @"xxxx.gif"; if ([url1 hasSuffix:@".rmvb"]||[url1 hasSuffix:@".avi"]) { NSLog(@"这是一个视频"); }else if ([url1 hasSuffix:@".jpg"]||[url1 hasSuffix:@".gif"]){ NSLog(@"这是一个图片"); } }
int main(int argc, const char * argv[]) { @autoreleasepool { NSString *url1 = @"https://www.xxxxxx.com"; //字符串的查找 //找特定的位置 NSRange r1 = [url1 rangeOfString:@"www"];
if (r1.location ==NSNotFound) { NSLog(@"没查到啊"); }else{ NSLog(@"loc = %lu,len = %lu",r1.location,r1.length); }
} return 0; }
|