NSString对象调用pathExtension属性,即可获得后缀名。
<NSPathUtilities.h>
@property (readonly, copy) NSString *pathExtension;
例如:
NSString *suffix = [sourceString.pathExtension lowercaseString];
if ([suffix isEqualToString:@"png"] ||
[suffix isEqualToString:@"jpg"] ||
[suffix isEqualToString:@"gif"] ||
[suffix isEqualToString:@"mp4"] ||
[suffix isEqualToString:@"mov"] ||
[suffix isEqualToString:@"com"] ||
[suffix isEqualToString:@"html"] ) {
[self doSomething];
}
网友评论