Java handles emoji emoticons

Source: Internet
Author: User

public class emojiutil {/** *  convert emoji expression in str to byte array  *  *  @param  str *  @return  */public static string resolvetobytefromemoji (string  STR)  {pattern pattern = pattern.compile ("[^ (\u2e80-\u9fff\\w\\s ' [email protected]#\\$ %\\^&\\*\\ (\ \) _+-? ()--=\\[\\]{}\\|;. ,、《》”:;“! ... ': ' \ ' <,>\\.? /\\\\*)]"); Matcher matcher = pattern.matcher (str); Stringbuffer sb2 = new stringbuffer ();while  (Matcher.find ())  { Matcher.appendreplacement (Sb2, resolvetobyte (matcher.group (0));} Matcher.appendtail (SB2); return sb2.tostring ();} /** *  emoji expression of byte array type in str to normal display emoji expression  *  *  @param  str * @ Return */public static string resolvetoemojifrombyte (STRING&NBSP;STR)  {Pattern  Pattern2 = pattern.compile ("<:([[-]\\d*[,]]+]:>"); Matcher matcher2 = pattern2.mAtcher (str); Stringbuffer sb3 = new stringbuffer ();while  (Matcher2.find ())  { Matcher2.appendreplacement (Sb3, resolvetoemoji (matcher2.group (0));} Matcher2.appendtail (SB3); return sb3.tostring ();} Private static string resolvetobyte (STRING&NBSP;STR)  {byte[] b =  Str.getbytes (); Stringbuffer sb = new stringbuffer (); Sb.append ("&LT;:");for  (int i = 0 ;  i < b.length; i++)  {if  (i < b.length - 1)  { Sb.append (Byte.valueof (B[i]). toString ()  +  ",");  else {sb.append (Byte.valueof (B[i]). toString ());}} Sb.append (":>"); return sb.tostring ();} Private static string resolvetoemoji (STRING&NBSP;STR)  {str = str.replaceall (" <: ", " "). ReplaceAll (":> ", " "); String[] s = str.split (",");byte[] b = new byte[s.length];for  (int  i = 0; i < s.length; i++)  {b[i] = byte.valueof (S[i]);} Return new string (b);}}


Java handles emoji emoticons

Related Article

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.