有没有更有效的方法来去除一串不受欢迎的短语,在这种情况下是图像扩展?我知道可以使用此处使用的 NSCharacterSet:Replace multiple characters in a string in Objective-C? 但对于整个短语?
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:@""];