SeparatedArray =[link
componentsSeparatedByString:@"/"];
filename = [SeparatedArray lastObject];
NSLog(@”%@”,SeparatedArray);
NSLog(@”%@”,filename);
[filename release];
方法三:将链接看成路径。
NSString * urlString =
@”http://www.baidu.com/img/baidu_logo_fqj_10.gif”;
NSArray *urlCom = [[NSArray alloc]initWithArray:[url
pathComponents]];
NSLog(@”%@”,[urlCom lastObject]);
[urlCom release];
方法四:NSRange.它在截取二进制文件的时候十分方便。
NSString * urlString =
@”http://www.baidu.com/img/baidu_logo_fqj_10.gif”;
NSString * fileName;
NSRange range = [urlString rangeOfString:@"/"
options:NSBackwardsSearch];
if (range.location != NSNotFound)
fileName = [urlString
substringFromIndex:range.location+1];
if([[fileName
lowercaseString]hasSuffix:@”.gif”])
NSLog(@”%@”,fileName);
return;