Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 154 Vote(s) - 3.64 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Objective-C: Extract filename from path string

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

What is the easiest way to do that?
Reply

#2
If you're displaying a user-readable file name, you do **not** want to use `lastPathComponent`. Instead, pass the full path to NSFileManager's `displayNameAtPath:` method. This basically does does the same thing, only it correctly localizes the file name and removes the extension based on the user's preferences.
Reply

#3
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
Reply

#4
Taken from [the NSString reference][1], 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.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through