
- //从路径中获得完整的文件名(带后缀)
 - exestr=[filePathlastPathComponent];
 - NSLog(@"%@",exestr);
 - //获得文件名(不带后缀)
 - exestr=[exestrstringByDeletingPathExtension];
 - NSLog(@"%@",exestr);
 - //获得文件的后缀名(不带'.')
 - exestr=[filePathpathExtension];
 - NSLog(@"%@",exestr);
 
- NSString*path=@"~/textFile.txt";
 - NSString*pathExtension=[pathpathExtension];
 - pathExtension这个字符串的值将是“txt”。句点将被去掉了。如果没有句点指明扩展名,将返回一个空串。如果文件不存在,也将返回空串
 
- [[imageNamecomponentsSeparatedByString:@"."]objectAtIndex:0]
 - 用.分开,objectAtIndex:0为文件名,objectAtIndex:1为后缀
 
- iPhone-获取网络数据或者路径的文件名
 - iPhone中,在网络中的数据流中提取链接中的文件名称时,有很多方法,这里总结一些。
 - 方法一:最直接。
 - NSString*urlString=@”http://www.baidu.com/img/baidu_logo_fqj_10.gif”;
 - NSString*fileName=[urlStringlastPathComponent];
 - NSLog(@”%@”,fileName);
 - 方法二:根据字符或者时字符串分割。
 - Object-C
 - NSString*link=@”http://www.baidu.com/img/baidu_logo_fqj_10.gif”;
 - NSString*filename=[[NSStringalloc]init];
 - NSArray*SeparatedArray=[[NSArrayalloc]init];
 - SeparatedArray=[linkcomponentsSeparatedByString:@"/"];
 - filename=[SeparatedArraylastObject];
 - NSLog(@”%@”,SeparatedArray);
 - NSLog(@”%@”,filename);
 - [filenamerelease];
 - 方法三:将链接看成路径。
 - NSString*urlString=@”http://www.baidu.com/img/baidu_logo_fqj_10.gif”;
 - NSArray*urlCom=[[NSArrayalloc]initWithArray:[urlpathComponents]];
 - NSLog(@”%@”,[urlComlastObject]);
 - [urlComrelease];
 - 方法四:NSRange.它在截取二进制文件的时候十分方便。
 - NSString*urlString=@”http://www.baidu.com/img/baidu_logo_fqj_10.gif”;
 - NSString*fileName;
 - NSRangerange=[urlStringrangeOfString:@"/"options:NSBackwardsSearch];
 - if(range.location!=NSNotFound)
 - {
 - fileName=[urlStringsubstringFromIndex:range.location+1];
 - if([[fileNamelowercaseString]hasSuffix:@”.gif”])
 - {
 - NSLog(@”%@”,fileName);
 - }
 - else
 - {
 - }
 - }
 - else
 - {
 - return;
 - }
 
爱华网



