Detects if the text inside the TextView contains emoji emoji characters

Source: Internet
Author: User

This method can be used to detect and return a bool value.

-(BOOL) Stringcontainsemoji: (NSString *)string{__block BOOL returnvalue=NO; [stringEnumeratesubstringsinrange:nsmakerange (0, [stringlength]) Options:nsstringenumerationbycomposedcharactersequences Usingblock:^ (NSString *substring, Nsrange substringrange, Nsrange enclosingrange, BOOL *stop) {                                                                ConstUnichar HS = [substring Characteratindex:0]; if(0xd800<= HS && HS <=0XDBFF) {                                                                        if(Substring.length >1) {                                                                                ConstUnichar ls = [substring characteratindex:1]; Const intUC = (HS-0xd800) *0x400) + (LS-0xdc00) +0x10000; if(0x1d000<= UC && UC <=0x1f77f) {returnvalue=YES;                                                                    }                                                                            } } Else if(Substring.length >1) {                                                                        ConstUnichar ls = [substring characteratindex:1]; if(ls = =0x20e3) {returnvalue=YES; }                                                                    } Else {                                                                        if(0x2100<= HS && HS <=0x27ff) {returnvalue=YES; } Else if(0x2b05<= HS && HS <=0x2b07) {returnvalue=YES; } Else if(0x2934<= HS && HS <=0x2935) {returnvalue=YES; } Else if(0x3297<= HS && HS <=0x3299) {returnvalue=YES; } Else if(HS = =0xa9|| HS = =0xae|| HS = =0x303d|| HS = =0x3030|| HS = =0x2b55|| HS = =0x2b1c|| HS = =0x2b1b|| HS = =0x2b50) {returnvalue=YES;                                                            }                                                                    }                }]; returnreturnvalue; }

This method can be added to the classification of the nsstring, or directly affixed to the current controller, in the upcoming text, or to click on the text to be sent to judge, you can use the bomb alertview to remind the re-input

This method is also found on the Internet, the specific source does not remember

Detects if the text inside the TextView contains emoji emoji characters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.