NSFileManager,文件扩展名
我正在创建一个 iPhone 应用程序,它使 iPhone 充当随身碟,以便轻松共享文件。
在第一阶段,我在目录中有一些文件(png,pdf,jpg,zip),我让它们以可变数组的形式显示在表格视图中。它显示在 tableView 中,如下所示,
.DS_Store
.localized
gazelle.pdf
Hamburger_sandwich.jpg
IITD TAJ Picture 028_jpg.jpg
iya_logo_final_b&w.jpg
manifesto09-eng.pdf
RSSReader.sql
SimpleURLConnections.zip
SQLTutorial
我只想显示文件名,不想显示扩展名。我知道可以在 NSFileManager 中提取文件的扩展名。但我不知道怎么办。请帮助我使我的表格视图看起来像这样
.DS_Store
.localized
gazelle
Hamburger_sandwich
IITD TAJ Picture 028_jpg
iya_logo_final_b&w
manifesto09-eng
RSSReader
SimpleURLConnections
SQLTutorial
I am creating an iPhone application which makes a iphone act as a pendrive for easy file sharing.
In the first stage, i have some files(png, pdf, jpg, zip) in a directory and i made them display in the tableview in the form of mutable array. It displays in the tableView as shown below,
.DS_Store
.localized
gazelle.pdf
Hamburger_sandwich.jpg
IITD TAJ Picture 028_jpg.jpg
iya_logo_final_b&w.jpg
manifesto09-eng.pdf
RSSReader.sql
SimpleURLConnections.zip
SQLTutorial
I just want to display the name of the files and i do not want to display the extensions. I know that it is possible to extract the extensions of a file in NSFileManager. But i do not know how. Please help me to make my table view look like this
.DS_Store
.localized
gazelle
Hamburger_sandwich
IITD TAJ Picture 028_jpg
iya_logo_final_b&w
manifesto09-eng
RSSReader
SimpleURLConnections
SQLTutorial
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 NSString 的文档,您会发现
stringByDeletingPathExtension
。基本思想是,您不想更新现有数组中的对象,而是创建一个文件名不带扩展名的新数组,并丢弃原始数组。
这是可以做到的:
我不希望您理解该代码,因此这里有一个更简单的版本:
Look into NSString's documentation, there you'll find
stringByDeletingPathExtension
.The basic idea is that you do not want to update objects in existing array, but create a new array with filenames without extension, and throw the original array away.
This is how it can be done:
I do not expect you to understand that code, therefore here's a more straightforward version: