java 中文转Unicode 以及 Unicode转中文
package com.sun;
public class Snippet {
public static void main(String[] args) {
String cn = "你";
System.out.println(cnToUnicode(cn));
// 字符串 : \u5f00\u59cb\u4efb\u52a1 ,由于 \ 在java里是转义字符,要写出下面这种形式
String unicode = "\\u4f60";
System.out.println(unicodeToCn(unicode));
}
private static String unicodeToCn(String unicode) {
/** 以 \ u 分割,因为java注释也能识别unicode,因此中间加了一个空格*/
String[] strs = unicode.split("\\\\u");
String returnStr = "";
// 由于unicode字符串以 \ u 开头,因此分割出的第一个字符是""。
for (int i = 1; i < strs.length; i++) {
returnStr += (char) Integer.valueOf(strs[i], 16).intValue();
}
return returnStr;
}
private static String cnToUnicode(String cn) {
char[] chars = cn.toCharArray();
String returnStr = "";
for (int i = 0; i < chars.length; i++) {
returnStr += "\\u" + Integer.toString(chars[i], 16);
}
return returnStr;
}
}
效果:
java 中文转Unicode 以及 Unicode转中文的更多相关文章
- java 中文转换成Unicode编码和Unicode编码转换成中文
转自:一叶飘舟 http://blog.csdn.net/jdsjlzx/article/details/ package lia.meetlucene; import java.io.IOExcep ...
- java对含有中文的字符串进行Unicode编码
public class MyUtil { public static void main(String[] args) throws Exception { String s = "a中a ...
- 中文字符串转换为十六进制Unicode编码字符串
package my.unicode; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Uni ...
- js 中文汉字转Unicode、Unicode转中文汉字、ASCII转换Unicode、Unicode转换ASCII、中文转换&#XXX函数代码
最近看不少在线工具里面都有一些编码转换的代码,很多情况下我们都用得到,这里脚本之家小编就跟大家分享一下这些资料 Unicode介绍 Unicode(统一码.万国码.单一码)是一种在计算机上使用的字符编 ...
- 解决JSON.stringify()自动将中文转译成unicode的方法
最近在工作中,发现在IE8下JSON.stringify()自动将中文转译为unicode编码,原本选择的中文字符,传到后台变为了unicode编码,即\u****的形式.查找资料后发现,与标准的JS ...
- "上市时间: 2014年秋冬季" unicode十进制编码转中文
"上市时间: 2014年秋冬季" unicode十进制编码转中文 System.Web.HttpUtility.HtmlDecode(tmp);
- jmeter接口测试--响应结果Unicode转码成中文
jmeter接口测试-响应结果Unicode转码成中文 一般情况下,接口返回数据都会经过加密,所以有时相应结果会显示为Unicode,因此,需添加BeanShell PostProcessor,加入代 ...
- 编码对象或者字串中包含Unicode字符怎样转换为中文
In [18]: c = '你好' In [20]: d = c.encode('unicode_escape') In [21]: d Out[21]: b'\\u4f60\\u597d' In [ ...
- Java 16进制、unicode互转
package service; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CodeCh ...
随机推荐
- CSU 2136 ——湖南多校对抗赛 I
2136: 统帅三军! Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 55 ...
- Hibernate中inverse="true"的理解
Hibernate中inverse="true"的理解 举例如下 转自:http://lijiejava.iteye.com/blog/776587 Customer类: publ ...
- 50 days before NOI2017
2017.5.31 今天开了这个博客,打算每天来写点东西,嗯...毕竟要NOI了嘛... 第一天跑到常州里集训,打开题目一看湖南集训题... T1刷一下写完,然后交了然后发现错了...赶紧改过来,大概 ...
- [译] 如何像 Python 高手一样编程?
转自:http://www.liuhaihua.cn/archives/23475.html Harries 发布于 7天前 分类:编程技术 阅读(15) 评论(0) 最近在网上看到一篇介绍Pytho ...
- 【linux高级程序设计】(第十二章)Linux多线程编程 4
读写锁 书上有读者写者的代码,我实在是懒得实现一遍了.跟之前的代码差不多. 多线程异步信号处理 int pthread_kill (pthread_t __threadid, int __signo) ...
- 【linux高级程序设计】(第九章)进程间通信-管道 3
有名管道 无名管道和有名管道: 1. 管道是特殊类型的文件,在满足先入先出的原则写可以读写,不能定位读写位置. 2.管道是单向的. 3.无名管道阻塞于读写位置,而有名管道阻塞在创建位置. 4.无名管道 ...
- bring to front 必须在右边的form上才生效。
- hihocoder1236(2015长春网赛J题) Scores(bitset && 分块)
题意:给你50000个五维点(a1,a2,a3,a4,a5),50000个询问(q1,q2,q3,q4,q5),问已知点里有多少个点(x1,x2,x3,x4,x5)满足(xi<=qi,i=1,2 ...
- win7下提权代码
inline BOOL SetPrivilege() { HANDLE hProcess, hToken; TOKEN_PRIVILEGES NewState; LUID luidPrivilegeL ...
- poj 3026(BFS+最小生成树)
Borg Maze Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12032 Accepted: 3932 Descri ...