import java.io.UnsupportedEncodingException;

public class TestUnicode{

/*
* 中文转unicode编码
*/
public static String gbEncoding(final String gbString) {
char[] utfBytes = gbString.toCharArray();
String unicodeBytes = "";
for (int i = 0; i < utfBytes.length; i++) {
String hexB = Integer.toHexString(utfBytes[i]);
if (hexB.length() <= 2) {
hexB = "00" + hexB;
}
unicodeBytes = unicodeBytes + "\\u" + hexB;
}
return unicodeBytes;
}
/*
* unicode编码转中文
*/
public static String decodeUnicode(final String dataStr) {
int start = 0;
int end = 0;
final StringBuffer buffer = new StringBuffer();
while (start > -1) {
end = dataStr.indexOf("\\u", start + 2);
String charStr = "";
if (end == -1) {
charStr = dataStr.substring(start + 2, dataStr.length());
} else {
charStr = dataStr.substring(start + 2, end);
}
char letter = (char) Integer.parseInt(charStr, 16); // 16进制parse整形字符串。
buffer.append(new Character(letter).toString());
start = end;
}
return buffer.toString();
}
}

最新文章

  1. Linux下查看chm文件
  2. PHP 时间 date,strtotime ,time计算1970开始的第几天
  3. n&amp;(n-1) n&amp;(-n)
  4. 怎样写 OpenStack Neutron 的 Extension (二)
  5. zabbix监控activemq队列脚本
  6. 10.3 noip模拟试题
  7. 深入理解ob_flush和flush的区别(转)
  8. 关于OC-省市区习题
  9. 刷新指定行或区 cell
  10. git-daemon的快捷搭建
  11. Hdu 1016 Prime Ring Problem (素数环经典dfs)
  12. 基于ReliefF和K-means算法的医学应用实例
  13. Map遍历四种常用方法
  14. DL4NLP —— seq2seq+attention机制的应用:文档自动摘要(Automatic Text Summarization)
  15. IntelliJ IDEA(二) :面板介绍
  16. nyoj Mod
  17. Array.from();Object.keys();Array.map()
  18. 内联元素于与块元素的转换 相对定位、绝对定位以及fixed定位 Z轴覆盖
  19. 菜鸟系列docker——docker镜像中(4)
  20. CentOS7 yum 安装 PHP 5.6.24

热门文章

  1. java中checked异常和unchecked异常区别?
  2. 论文阅读总结-Patient clustering improves efficiency of federated machine learning to predict mortality and hospital stay time using distributed electronic medical records
  3. Java自定义异常类的简单实现
  4. vue后台管理系统组件弹窗
  5. LC-707
  6. kubectl creat -f 创建pod时出错
  7. 论文解读(S^3-CL)《Structural and Semantic Contrastive Learning for Self-supervised Node Representation Learning》
  8. windows批处理执行图片爬取脚本
  9. 【深入理解TcaplusDB技术】扫描数据接口说明——[List表]
  10. 『现学现忘』Git基础 — 11、配置Git用户签名的方式