Processing of emoji expressions in Java strings

Source: Internet
Author: User

In doing a global search, encountered in the content of mobile phone expression, stored in the database is an error. Online search for a long time, found that many people do not go to experiment to copy other people's Code online hair, and then led me to use direct not. Finally found a way to do, summed up in this:

There are two main methods:
First, modify the database character set:
This method requires the hard requirements of your MySQL database version 5.5 later. Generally have database management tools, directly opened the change is, for example, I used the heidisql, directly to the table to UTF8MB4 on it. This approach is simple and easy, but you may need to restart the database. Another problem is that sometimes this method is not very good, the first time I used this method to solve the problem perfectly, but the second time, said nothing. Therefore, this way is still not recommended.

Second, filter out these expressions.
Now that the database can't be saved, just filter these expressions off. This situation is a way to make the service more convenient by damaging the customer's personality. At present many websites are doing so, after all efficiency is the key, you this expression even if save, also perhaps where again use, show not.
It is suggested that the tool method is convenient, practical and feasible.

/**
     * Emoji expression Replacement
     * *
     @param Source Original String
     * @param slipstr emoji expression replaced by the string                
     * @return Filtered String *
     * Public
    static String Filteremoji (String   
    source,string slipstr) {  
        if (Stringutils.isnotblank (source)) { return
            Source.replaceall ("[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]", slipstr);
        } else{return
            source;
        }
    

Original: http://www.3fwork.com/b200/004985MYM000642/

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.