且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Objective-C:从路径字符串中提取文件名

更新时间:2023-02-23 18:32:20

取自 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.