package utils;

import org.apache.commons.lang3.StringUtils;

public class UnicodeUtils {

    public static String unicode2String(String unicode){
if(StringUtils.isBlank(unicode))return null;
StringBuilder sb = new StringBuilder();
int i = -1;
int pos = 0; while((i=unicode.indexOf("\\u", pos)) != -1){
sb.append(unicode.substring(pos, i));
if(i+5 < unicode.length()){
pos = i+6;
sb.append((char)Integer.parseInt(unicode.substring(i+2, i+6), 16));
}
} return sb.toString();
} public static String string2Unicode(String string) { if(StringUtils.isBlank(string))return null;
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();
} public static void main(String[] args) {
String string=UnicodeUtils.unicode2String("\\u4e0e\\u4e2d\\u6587\\u7684\\u8f6c\\u6362");
System.out.println(string); String unicode=UnicodeUtils.string2Unicode("Unicode与中文的转换");
System.out.println(unicode); }
}

输出结果:

与中文的转换
\u55\u6e\u69\u63\u6f\u64\u65\u4e0e\u4e2d\u6587\u7684\u8f6c\u6362

java-Unicode与中文的转换的更多相关文章

  1. python unicode转中文及转换默认编码

    一. 在爬虫抓取网页信息时常需要将类似"\u4eba\u751f\u82e6\u77ed\uff0cpy\u662f\u5cb8"转换为中文,实际上这是unicode的中文编码.可 ...

  2. java unicode转中文

    public static String unicodeToString(String str) { Pattern pattern = Pattern.compile("(\\\\u(\\ ...

  3. java Unicode和UTF-8之间转换

    utf-8转unicode public static String utf8ToUnicode(String inStr) { char[] myBuffer = inStr.toCharArray ...

  4. js 中文汉字转Unicode、Unicode转中文汉字、ASCII转换Unicode、Unicode转换ASCII、中文转换&#XXX函数代码

    最近看不少在线工具里面都有一些编码转换的代码,很多情况下我们都用得到,这里脚本之家小编就跟大家分享一下这些资料 Unicode介绍 Unicode(统一码.万国码.单一码)是一种在计算机上使用的字符编 ...

  5. Python2.X如何将Unicode中文字符串转换成 string字符串

    Python2.X如何将Unicode中文字符串转换成 string字符串   普通字符串可以用多种方式编码成Unicode字符串,具体要看你究竟选择了哪种编码:unicodestring = u&q ...

  6. c# unicode 编码 中文转换 已测试(转)

    中文传参时因为编码不同经常凌乱风中,故传前编成unicode码来过度是一个不错的解决方法 /// <summary> /// 中文转unicode        /// </summ ...

  7. Java编程中中文乱码问题的研究及解决方案

    0 引言 Java最大的特性是与平台的无关性及开发环境的多样性.字符串被Java应用程序转化之前,是根据操作系统默认的编码方式编码.Java语言内部采用Unicode编码,它是定长双字节编码,即任何符 ...

  8. Java IO---缓冲流和转换流

    一. 缓冲流 ​ 缓冲流是处理流的一种,也叫高效流,是对4个基本输入输出流的增强,它让输入输出流具有1个缓冲区,能显著减小与外部的IO次数,从而提高读写的效率,并且提供了一些额外的读写方法. ​ 因为 ...

  9. 将http调用返回json中的有关中文的unicode转换为中文

    在http调用时获取到的json数据中文是乱码的解决方法: 中文转Unicode:HttpUtility.UrlEncodeUnicode(string str);转换后中文格式:"%uxx ...

随机推荐

  1. 将 django部署到 heroku上

    为什么要这样做,因为我并没有弄懂,使用传统和推荐的方法来部署django.刚好我手里有这么一份教程我就按照这么做了. 1. 访问 http://heroku.com/ 完成一个注册,注册需要一个国外的 ...

  2. ubuntu下安装bin文件

    从Java官网下载的安装文件,有的只有bin文件,没有.tar.gz文件. ①进入设备终端,通过sudo -s或su回车,切换到管理员用户:②输入管理员密码然后回车:③输入sudo chmod +x ...

  3. HDU 6228 - Tree - [DFS]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  4. SQL Fundamentals || Oracle SQL语言

    对于SQL语言,有两个组成部分: DML(data manipulation language) 它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据 ...

  5. hive中的几个参数:元数据配置、仓库位置、打印表字段相关参数

    hive仓库位置由以下参数决定,默认位置/user/hive/warehouse: <property>         <name>hive.metastore.wareho ...

  6. [skill] 异或

    都怪学习不好,或者老师教的不好.虽然知道异或的算法,但是始终不明白,到底有什么意义...直到今天,终于明白了. 还是应该怪我学的不好,不能怪老师. 今天有一个应用场景,写一个函数.这是一个hash表的 ...

  7. c++中new的三种用法详细解析

    转载至: http://www.jb51.net/article/41524.htm 以下的是对c++中new的三种使用方法进行了详细的分析介绍,需要的朋友可以过来参考下,希望对大家有所帮助. 一. ...

  8. 2018/05/07 Linux find命令中{}的作用

    首先抛出一个问题,如果你在文件中建立了一个 -a.txt 的文件,你会怎么删除它? 我之前的回答是 rm -a.txt 实验结果很明显,不能删除. 因为在 Linux 下,会把 -a.txt 前面的 ...

  9. HashMap如何解决取Value值为Null

    场景: 用HashMap方法时候,取Keys时候自认为敲的肯定是准确无误,然后能得到对应的Values 值.  但写脚本代码时候不好习惯,没事总喜欢敲个空格建,导致取Keys之后多空格. Featur ...

  10. css样式重置样式

    html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, ci ...