Trim file extension UITableView
I want to trim the file extension from text I have an NSMutableArray
in table cells.
NSMutableArray *theFiles = [NSMutableArray new];
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:@"/Test"];
for (NSString *s in fileList){
[theFiles addObject:fileList];
}
cell.textLabel.text = theFiles[indexPath.row];
return cell;
This lists for exampl开发者_开发百科e "Xylophone.m4r" I want to remove the .m4r.
Try -[NSString stringByDeletingPathExtension]
(in NSPathUtilities.h).
Actually, for my use, I was able to create a plist programmatically and just not use an extension and it works great! However, anothe rway to do this is:
[string stringByReplacingOccurrencesOfString:@".fileextension" withString:@""];
Just have to delete path extension component:
cell.textLabel.text = [[theFiles objectAtIndex:indexPath.row] stringByDeletingPathExtension];
精彩评论