美文网首页
NSString剔除emoji表情

NSString剔除emoji表情

作者: 乡道狗毛草 | 来源:发表于2016-03-07 16:24 被阅读202次

给NSString 写个分类

@implementation NSString(EmojiExtension)

- (NSString*)removeEmoji {

__block NSMutableString* temp = [NSMutableString    string];

[self enumerateSubstringsInRange: NSMakeRange(0,     [self length])     options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange,    NSRange enclosingRange, BOOL *stop){const unichar hs = [substring characterAtIndex: 0];

// surrogate pair

if (0xd800 <= hs && hs <= 0xdbff) {const unichar ls = [substring characterAtIndex: 1];
const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
[temp appendString: (0x1d000 <= uc && uc <= 0x1f77f)? @"": substring]; // U+1D000-1F77F

// non surrogate

} else {
[temp appendString: (0x2100 <= hs && hs <= 0x26ff)? @"": substring]; // U+2100-26FF

}

}];

return temp;

}

@end

这是文献

相关文章

网友评论

      本文标题:NSString剔除emoji表情

      本文链接:https://www.haomeiwen.com/subject/psaakttx.html