Objective-C:从路径字符串中提取文件名 [英] Objective-C: Extract filename from path string
本文介绍了Objective-C:从路径字符串中提取文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我有 NSString
和 /Users/user/Projects/thefile.ext
我想提取<$
When I have NSString
with /Users/user/Projects/thefile.ext
I want to extract thefile
with Objective-C methods.
这是最简单的方法是什么?
What is the easiest way to do that?
推荐答案
取自 NSString参考,可以使用:
NSString *theFileName = [[string lastPathComponent] stringByDeletingPathExtension];
lastPathComponent
调用将返回 thefile.ext
, stringByDeletingPathExtension
将从末尾删除扩展名。
The lastPathComponent
call will return thefile.ext
, and the stringByDeletingPathExtension
will remove the extension suffic from the end.
这篇关于Objective-C:从路径字符串中提取文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文