<pre name="code" class="cpp">// 从路径中获得完整的文件名(带后缀) exestr = [filePath lastPathComponent]; NSLog(@"%@",exestr);// 获得文件名(不带后缀)exestr = [exestr stringByDeletingPathExtension]; NSLog(@"%@",exestr);// 获得文件的扩展类型(不带'.') exestr = [filePath pathExtension]; NSLog(@"%@",exestr);</pre><br><pre name="code" class="php">NSString *path = @"~/textFile.txt";NSString *pathExtension = [path pathExtension];pathExtension这个字符串的值将是“txt”。句点将被去掉了。如果没有句点指明扩展名,将返回一个空串。如果文件不存在,也将返回空串 </pre><br><br><pre name="code" class="php">[[imageName componentsSeparatedByString:@"."] objectAtIndex:0]用.分开, objectAtIndex:0为文件名, objectAtIndex:1为后缀 </pre><br><pre name="code" class="cpp">iPhone-获取网络数据或者路径的文件名iPhone中,在网络中的数据流中提取链接中的文件名称时,有很多方法,这里总结一些。方法一:最直接。NSString * urlString = @”http://www.baidu.com/img/baidu_logo_fqj_10.gif”;NSString *fileName = [urlString lastPathComponent];NSLog(@”%@”,fileName);方法二:根据字符或者时字符串分割。Object -CNSString *link = @”http://www.baidu.com/img/baidu_logo_fqj_10.gif”;NSString *filename = [[NSString alloc] init];NSArray *SeparatedArray = [[NSArray alloc]init];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);}else{}}else{return;}</pre><br><br><pre></pre><div id="livemargins_control" style="position:absolute; z-index:9999"><img src="" alt="" height="5" width="77" style="position:absolute; left:-77px; top:-5px"></div><div id="livemargins_control" style="position:absolute; z-index:9999; top:220px; left:5px; width:1px; height:1px"><img src="" alt="" height="5" width="77" style="position:absolute; left:-77px; top:-5px"></div><pre></pre><div id="livemargins_control" style="position:absolute; z-index:9999"><img src="" alt="" height="5" width="77" style="position:absolute; left:-77px; top:-5px"><img src="" alt="" style="position:absolute; left:0; top:-5px"><img id="monitor-play-button" src="" alt="" style="position:absolute; left:1px; top:0"></div><pre></pre><div id="livemargins_control" style="position:absolute; z-index:9999"><img src="" alt="" height="5" width="77" style="position:absolute; left:-77px; top:-5px"><img src="" alt="" style="position:absolute; left:0; top:-5px"><img id="monitor-play-button" src="" alt="" style="position:absolute; left:1px; top:0"></div><pre></pre><div id="livemargins_control" style="position:absolute; z-index:9999"><img src="" alt="" height="5" width="77" style="position:absolute; left:-77px; top:-5px"><img src="" alt="" style="position:absolute; left:0; top:-5px"><img id="monitor-play-button" src="" alt="" style="position:absolute; left:1px; top:0"></div><pre></pre><div id="livemargins_control" style="position:absolute; z-index:9999"><img src="" alt="" height="5" width="77" style="position:absolute; left:-77px; top:-5px"><img src="" alt="" style="position:absolute; left:0; top:-5px"><img id="monitor-play-button" src="" alt="" style="position:absolute; left:1px; top:0"></div><pre></pre><div id="livemargins_control" style="position:absolute; z-index:9999"><img src="" alt="" height="5" width="77" style="position:absolute; left:-77px; top:-5px"><img src="" alt="" style="position:absolute; left:0; top:-5px"><img id="monitor-play-button" src="" alt="" style="position:absolute; left:1px; top:0"></div><pre></pre><div id="livemargins_control" style="position:absolute; z-index:9999"><img src="" height="5" width="77" alt="" style="position:absolute; left:-77px; top:-5px"><img src="" alt="" style="position:absolute; left:0; top:-5px"> <img id="monitor-play-button" src="" alt="" style="position:absolute; left:1px; top:0"></div>
?