Restituisce il nome di un file a partire dall’oggetto NSURLRequest, permettendo di decidere se avere o meno la sue estensione:
1 2 3 4 5 6 7 8 | - (NSString *)getFilenameFromRequest:(NSURLRequest *)request avoidExtension:(BOOL)avoidExtension { NSString *filePath = [[[request URL] path] lastPathComponent]; if (avoidExtension) { NSArray *a = [filePath componentsSeparatedByString:@"."]; return [a objectAtIndex:0]; } return filePath; } |
Restituisce (similmente a sopra) la sola estensione di un file partnedo sempre da un oggetto NSURLRequest:
1 2 3 4 5 | - (NSString *)getExtensionFromRequest:(NSURLRequest *)request { NSString *filePath = [[[request URL] path] lastPathComponent]; NSArray *a = [filePath componentsSeparatedByString:@"."]; return [a objectAtIndex:1]; } |
Ecco come comvertire un indirizzo da NSString a NSURL e vice versa:
1 2 3 4 5 6 7 8 | NSString *filePath = @"/path/filetext.txt"; // ... NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: filePath]; // fare la release // oppure, che è uguale NSURL fileURL = [NSURL fileURLWithPath: filePath]; // autorelease // Contrario: NURL -> NSString NSString *filePath = [fileUrl absoluteString]; |








4
Non ci sono commenti per questo Post
Lascia un commento