gistfile1.txt /** * 对表情进行转义成utf-8 * * @param str * @return */public static String emojiConvert1(String str) {String patternString = "([\\x{10000}-\\x{10ffff}\ud800-\udfff])";Pattern pattern = Pattern.compile(patternString);M
/** * 对表情进行转义成utf-8 * * @param str * @return */ public static String emojiConvert1(String str) { String patternString = "([\\x{10000}-\\x{10ffff}\ud800-\udfff])"; Pattern pattern = Pattern.compile(patternString); Matcher matcher = pattern.matcher(str); StringBuffer sb = new StringBuffer(); while (matcher.find()) { try { matcher.appendReplacement(sb, "[[" + URLEncoder.encode(matcher.group(1), "UTF-8") + "]]"); } catch (Exception e) { } } matcher.appendTail(sb); return sb.toString(); } /** * 对数据进行表情转换 * * @param str * @return */ public static String emojiRecovery2(String str) { String patternString = "\\[\\[(.*?)\\]\\]"; Pattern pattern = Pattern.compile(patternString); Matcher matcher = pattern.matcher(str); StringBuffer sb = new StringBuffer(); while (matcher.find()) { try { matcher.appendReplacement(sb, URLDecoder.decode(matcher.group(1), "UTF-8")); } catch (UnsupportedEncodingException e) { } } matcher.appendTail(sb); return sb.toString(); }