NSString * urlString = @"http://www.baidu.com/img/baidu_logo_fqj_10.gif";
//方法一:最直接
NSString * fileName = [urlString lastPathComponent];
NSLog(@"fileName==%@",fileName);
//方法二:根据字符或者字符串分割
NSString * fileName2 = [[NSString alloc] init];
NSArray * separatedArray = [[NSArray alloc] init];
separatedArray = [urlString componentsSeparatedByString:@"/"];
fileName2 = [separatedArray lastObject];
NSLog(@"separatedArray==%@",separatedArray);
NSLog(@"fileName2==%@",fileName2);
//方法三:将链接看成是路劲
NSArray * urlCom = [[NSArray alloc] initWithArray:[urlString pathComponents]];
NSLog(@"[urlCom lastObject]===%@",[urlCom lastObject]);
//方法四:NSRange.它在截取二进制文件的时候十分方便
NSString * fileName3;
NSRange range = [urlString rangeOfString:@"/" options:NSBackwardsSearch];//NSBackwardsSearch从字符串末尾开始检索
if (range.location != NSNotFound) {
fileName3 = [urlString substringFromIndex:range.location+];
if ([[fileName3 lowercaseString] hasSuffix:@".gif"]) {//lowercaseString 改变字母为小写 uppercaseString改变字母切大写 capitalizedString 首字母大些转换 ·
NSLog(@"fileName3====%@",fileName3);
}else{ }
}else{ }
05-14 18:45