Objective-C: Extract filename from path string

前端 未结 3 2020
面向向阳花
面向向阳花 2020-12-12 10:09

When I have NSString with /Users/user/Projects/thefile.ext I want to extract thefile with Objective-C methods.

What is the eas

3条回答
  •  攒了一身酷
    2020-12-12 10:52

    At the risk of being years late and off topic - and notwithstanding @Marc's excellent insight, in Swift it looks like:

    let basename = NSURL(string: "path/to/file.ext")?.URLByDeletingPathExtension?.lastPathComponent
    

提交回复
热议问题