java 转换emoji表情特殊字符的方法

如:名称 会过滤成名称

public class EmojiCharUtils {
    /**
     * 转换emoji表情特殊字符的方法
     * @param chars
     * @return
     */
    public static String transform(String chars){
        if (StringUtils.isEmpty(chars)){
            return chars;
        }
        StringBuilder emojiChars = new StringBuilder();
        int l = chars.length();
        for (int i = 0; i < l; i++) {
            char _s = chars.charAt(i);
            if (isEmojiCharacter(_s)) {
                emojiChars.append(_s);
            }
        }
        return emojiChars.toString();
    }

    public static boolean isEmojiCharacter(char codePoint) {
        return (codePoint == 0x0) ||
                (codePoint == 0x9) ||
                (codePoint == 0xA) ||
                (codePoint == 0xD) ||
                ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||
                ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) ||
                ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF));
    }

}

如果你是湖南的 欢迎加入 湖南人在深圳-Java群:557651502

你可能感兴趣的:(java)