When I have NSString with /Users/user/Projects/thefile.ext I want to extract thefile with Objective-C methods.
NSString
/Users/user/Projects/thefile.ext
thefile
What is the easiest way to do that?
Taken from the NSString reference, you can use :
NSString *theFileName = [[string lastPathComponent] stringByDeletingPathExtension];
The lastPathComponent call will return thefile.ext, and the stringByDeletingPathExtension will remove the extension suffix from the end.
lastPathComponent
thefile.ext
stringByDeletingPathExtension
2.1m questions
2.1m answers
60 comments
57.0k users