iOS判断字符串是否包含表情字符
1 - (BOOL)isContainsEmoji:(NSString *)string { 2 __block BOOL isEomji = NO; 3 [string enumerateSubstringsInRange:NSMakeRange(0, [string length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock: 4 ^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { 5 const unichar hs = [substring characterAtIndex:0]; 6 if (0xd800 <= hs && hs <= 0xdbff) { 7 if (substring.length > 1) { 8 const unichar ls = [substring characterAtIndex:1]; 9 const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000; 10 if (0x1d000 <= uc && uc <= 0x1f77f) { 11 isEomji = YES; 12 } 13 } 14 } else if (substring.length > 1) { 15 const unichar ls = [substring characterAtIndex:1]; 16 if (ls == 0x20e3 || ls == 0xfe0f) { 17 isEomji = YES; 18 } 19 } else { 20 if (0x2100 <= hs && hs <= 0x27ff && hs != 0x263b) { 21 isEomji = YES; 22 } else if (0x2B05 <= hs && hs <= 0x2b07) { 23 isEomji = YES; 24 } else if (0x2934 <= hs && hs <= 0x2935) { 25 isEomji = YES; 26 } else if (0x3297 <= hs && hs <= 0x3299) { 27 isEomji = YES; 28 } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50|| hs == 0x231a ) { 29 isEomji = YES; 30 } 31 } 32 }]; 33 return isEomji; 34 }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。