是否有更有效的方法來剝離一串不需要的短語,在這種情況下是圖像擴展?我知道可以使用這裏使用的NSCharacterSet:Replace multiple characters in a string in Objective-C?但是整個短語?更高效的stringByReplacingOccurrencesOfString方法
NSString *title = [imagePath lastPathComponent];
title = [title stringByReplacingOccurrencesOfString:@".JPG" withString:@""];
title = [title stringByReplacingOccurrencesOfString:@".JPEG" withString:@""];
title = [title stringByReplacingOccurrencesOfString:@".PNG" withString:@""];
title = [title stringByReplacingOccurrencesOfString:@".jpg" withString:@""];
title = [title stringByReplacingOccurrencesOfString:@".jpeg" withString:@""];
title = [title stringByReplacingOccurrencesOfString:@".png" withString:@""];