emoji表情等特殊字符处理和存储的两个方案
方案1.改数据库配置 使之支持emoji表情等特殊字符,小公司或者个人开发还好,大公司用此方案代价较大。 以mysql为例,改配置方法参考:https://blog.csdn.net/u010737354/article/details/52456668 方案2.使用unicode编码(推荐使用) 统一标准:入库或入缓存统一对特殊字符unicode编码,从库或缓存取出后统一进行unicode编码 (1)unicode加密: //加密emoji表情 public static String encodeToUnicode(String string) { StringBuffer unicode = new StringBuffer(); for (int i = 0; i < string.length(); i++) { // 取出每一个字符 char c = string.charAt(i); // 转换为unicode unicode.append("\\u" + Integer.toHexString(c)); } return unicode.toString(); } (2)unicode解密: //解密emoji表情 public static String decodeFromUnicode(String unicode) { StringBuffer string = new StringBuffer(); String[] hex = unicode.split("\\\\u"); if(hex.length==1){ return unicode; } for (int i = 1; i < hex.length; i++) { // 转换出每一个代码点 int data = Integer.parseInt(hex[i], 16); // 追加成string string.append((char) data); } return string.toString(); }
emoji表情等特殊字符处理和存储的两个方案_透明大脑-CSDN博客_emoji表情存储
---------------------------------------------------------------------------
国之殇,未敢忘!
南京大屠杀!
731部队!
以及核污染水排海等一系列全无人性的操作,购买他们的食品和为它们提供帮助只会更加变本加厉的害你,呼吁大家不要购买日本相关产品
昭昭前事,惕惕后人
吾辈当自强,方使国不受他人之侮!
---------------------------------------------------------------------------
作者:三号小玩家
出处:https://www.cnblogs.com/q1359720840/
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。 版权信息