Unicode和中午互转
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();
}
}
最新文章
- Linux下查看chm文件
- PHP 时间 date,strtotime ,time计算1970开始的第几天
- n&;(n-1) n&;(-n)
- 怎样写 OpenStack Neutron 的 Extension (二)
- zabbix监控activemq队列脚本
- 10.3 noip模拟试题
- 深入理解ob_flush和flush的区别(转)
- 关于OC-省市区习题
- 刷新指定行或区 cell
- git-daemon的快捷搭建
- Hdu 1016 Prime Ring Problem (素数环经典dfs)
- 基于ReliefF和K-means算法的医学应用实例
- Map遍历四种常用方法
- DL4NLP —— seq2seq+attention机制的应用:文档自动摘要(Automatic Text Summarization)
- IntelliJ IDEA(二) :面板介绍
- nyoj Mod
- Array.from();Object.keys();Array.map()
- 内联元素于与块元素的转换 相对定位、绝对定位以及fixed定位 Z轴覆盖
- 菜鸟系列docker——docker镜像中(4)
- CentOS7 yum 安装 PHP 5.6.24
热门文章
- java中checked异常和unchecked异常区别?
- 论文阅读总结-Patient clustering improves efficiency of federated machine learning to predict mortality and hospital stay time using distributed electronic medical records
- Java自定义异常类的简单实现
- vue后台管理系统组件弹窗
- LC-707
- kubectl creat -f 创建pod时出错
- 论文解读(S^3-CL)《Structural and Semantic Contrastive Learning for Self-supervised Node Representation Learning》
- windows批处理执行图片爬取脚本
- 【深入理解TcaplusDB技术】扫描数据接口说明——[List表]
- 『现学现忘』Git基础 — 11、配置Git用户签名的方式