Emoji过滤

2018/04/02 10:12
阅读数 26
private static boolean isNotEmojiCharacter(char codePoint)
{
    return (codePoint == 0x0) ||
        (codePoint == 0x9) ||
        (codePoint == 0xA) ||
        (codePoint == 0xD) ||
        ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) ||
        ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) ||
        ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF));
}

/**
 * 过滤emoji 或者 其他非文字类型的字符
 * @param source
 * @return
 */
public static String filterEmoji(String source)
{
    int len = source.length();
    StringBuilder buf = new StringBuilder(len);
    for (int i = 0; i < len; i++)
    {
        char codePoint = source.charAt(i);
        if (isNotEmojiCharacter(codePoint))
        {
            buf.append(codePoint);
        }
    }
    return buf.toString();

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部
返回顶部
顶部