2009-11-16 14 views
9

Voglio tagliare l'estensione del file dal testo Ho un NSMutableArray nelle celle della tabella.Estensione file Trim UITableView

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; 

elencati nel presente per esempio "Xylophone.m4r" Voglio rimuovere il .m4r.

+1

bene , il modo migliore con cui ho avuto fortuna è di non usare affatto un'estensione per il mio file. Finché ho creato il file usando il metodo XML, legge ancora il file, anche senza che l'estensione ci sia! – WrightsCS

risposta

38

Provare -[NSString stringByDeletingPathExtension] (in NSPathUtilities.h).

+0

per un NSMutableArray – WrightsCS

+1

Si sta già iterando attraverso l'array, basta fare qualcosa come [theFiles addObject: [s stringByDeletingPathExtension]]. –

3

In realtà, per il mio utilizzo, sono stato in grado di creare un plist in modo programmatico e non utilizzare un'estensione e funziona benissimo! Tuttavia, anothe Norvegia, a fare questo è:

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

Anche se la questione è più vecchio, è possibile utilizzare stringa:

NSString *yourFileName = @"Xylophone.m4r"; 
yourFileName = [yourFileName substringToIndex:yourFileName.length - 4]; 
0

resta che eliminare componente di estensione percorso:

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