【问题标题】:Trim file extension UITableView修剪文件扩展名 UITableView
【发布时间】:2009-11-16 06:26:26
【问题描述】:

我想从文本中删除文件扩展名,我在表格单元格中有一个 NSMutableArray

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;

此列表例如 "Xylophone.m4r" 我要删除 .m4r

【问题讨论】:

  • 好吧,我遇到的最好的方法是完全不为我的文件使用扩展名。只要我使用 XML 方法创建文件,它仍然会读取文件,即使没有扩展名!

标签: nsstring nsmutablearray trim


【解决方案1】:

试试-[NSString stringByDeletingPathExtension](在 NSPathUtilities.h 中)。

【讨论】:

  • 您已经在遍历数组,只需执行类似 [theFiles addObject: [s stringByDeletingPathExtension]] 的操作。
【解决方案2】:

实际上,就我的使用而言,我能够以编程方式创建一个 plist,只是不使用扩展名,而且效果很好!但是,另一种方法是:

[string stringByReplacingOccurrencesOfString:@".fileextension" withString:@""];

【讨论】:

    【解决方案3】:

    只需要删除路径扩展组件:

    cell.textLabel.text = [[theFiles objectAtIndex:indexPath.row] stringByDeletingPathExtension];
    

    【讨论】:

      猜你喜欢
      • 2013-04-10
      • 2017-01-21
      • 2016-01-05
      • 2011-05-14
      • 2010-10-30
      • 2015-10-20
      • 2015-03-27
      • 1970-01-01
      相关资源
      最近更新 更多