How to not include file extension while reading from Document directory?
-
08-03-2021 - |
Question
I am developing an application where i am creating some random .txt file which ultimately stored as a txt file format.
Now for reading these file i am using this code
NSString* documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSError* error = nil;
myArray = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentDirectory error:&error]retain];
Now i am displaying the file name in a table view using
cell.textLabel.text = [myArray objectAtIndex:row];
So it curretly displaying like file1.txt,file2.txt etc.
But i donot want the file extension while displaying in the table list.
How can i do that?
Solution
cell.textLabel.text = [[myArray objectAtIndex:row] stringByDeletingPathExtension];
OTHER TIPS
Use [yourString stringByDeletingPathExtension]
method to remove the extensions from your string. Refer NSString class.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow