当我有NSString我/Users/user/Projects/thefile.ext想thefile用Objective-C方法提取时。
NSString
/Users/user/Projects/thefile.ext
thefile
最简单的方法是什么?
取自NSString 参考,您可以使用:
NSString *theFileName = [[string lastPathComponent] stringByDeletingPathExtension];
lastPathComponent调用将返回,thefile.ext并且stringByDeletingPathExtension将从末尾删除扩展后缀。
lastPathComponent
thefile.ext
stringByDeletingPathExtension