Java过滤emoji表情,找出emoji的unicode范围。


/**
* 过滤Emoji表情 * @author Kunjie * 2015年7月17日 */ public class EmojiFilter { public static void main(String[] args) { System.out.println(filter("啊阿萨德发秦莞尔")); } public static String filter(String str){ if(str == null || str.length() == 0){ return ""; } StringBuffer sb = new StringBuffer(); for(int i=0;i<str.length()-1;i++){ int ch = str.charAt(i); int min = Integer.parseInt("E001", 16); int max = Integer.parseInt("E537", 16); if(ch >= min && ch <= max){ sb.append(""); }else{ sb.append((char)ch); } } return sb.toString(); } }

 

每个表情有 sb unicode编码。

如太阳表情,则sb码为E04A,是16进制的。

从中找到最小的 E001, E537,

然后将其转换为10进制比较大小。在这个范围内,就是emoji的表情字符了。

 

posted @ 2015-07-17 17:14  精进中的昆杰  阅读(4908)  评论(0编辑  收藏  举报