unicode编码与解码,代码如下

 package com.fenqiguanjia.api.services;

 /**
* Created by daixianjun on 2017/9/3.
*/ import org.apache.commons.lang.StringUtils; public class UnicodeUtils { /***
* unicode 编码与解码
* v\u003d0; cookie2\u003d161b41dbe306333ef031fccf315df69a;
* 转成: v=0; cookie2=161b41dbe306333ef031fccf315df69a;
* @param unicode
* @return
*/
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));
}
} if (pos < unicode.length()){
sb.append(unicode.substring(pos));
} 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();
}
}

unicode编码与解码的更多相关文章

  1. PHP中对汉字进行UNICODE编码和解码的实现

    <?php /** PHP中对汉字进行UNICODE编码和解码的实现 **/ class Helper_Tool{ //php中的unicode编码转中文 static function uni ...

  2. C# Unicode编码与解码方法

    public static class ExtentMethod { public static string ToUnicodeString(this string str) { StringBui ...

  3. java基础52 编码与解码

    1.解码与编码的含义 编码:把看得懂的字符变成看不懂的码值,这个过程就叫编码    解码:根据码值查到相对应的字符,我们把这个过程就叫解码 注意:编码与解码时,我们一般使用统一的码表,否则非常容易出现 ...

  4. Day 19:Properties配置文件类、打印流(printStream) 、 编码与解码

    Properties(配置文件类): 主要用于生产配置文件与读取配置文件的信息. Properties要注意的细节:  1. 如果配置文件的信息一旦使用了中文,那么在使用store方法生成配置文件的时 ...

  5. Unicode编码解码在线转换工具

    // Unicode编码解码在线转换工具 Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standar ...

  6. RapidJSON 代码剖析(三):Unicode 的编码与解码

    根据 RFC-7159: 8.1 Character Encoding JSON text SHALL be encoded in UTF-8, UTF-16, or UTF-32. The defa ...

  7. [SAP ABAP开发技术总结]字符编码与解码、Unicode

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  8. PHP解码unicode编码中文字符代码示例

    在抓取某网站数据,结果在数据包中发现了一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......", 这其实是中文被unicode编码后了的数据,想 ...

  9. C# \uxxx Unicode编码解码

    /// <summary> /// Unicode编码 /// </summary> /// <param name="str"></pa ...

随机推荐

  1. pyQt 流布局的一个例子

    瀑布流布局 from PyQt5.QtCore import QPoint, QRect, QSize, Qt from PyQt5.QtWidgets import (QApplication, Q ...

  2. 调用新浪短地址转换api的一个测试

    import base64 import requests url="http://www.~~~~.com" headers={ "User-Agent":& ...

  3. keras字符编码

    https://www.jianshu.com/p/258a21ae0390https://blog.csdn.net/apengpengpeng/article/details/80866034#- ...

  4. LeetCode——15. 三数之和

    给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复的三元组. ...

  5. [Algo] 625. Longest subarray contains only 1s

    Given an array of integers that contains only 0s and 1s and a positive integer k, you can flip at mo ...

  6. 吴裕雄--天生自然TensorFlow高层封装:解决ImportError: cannot import name 'tf_utils'

    将原来版本的keras卸载了,再安装2.1.5版本的keras就可以了.

  7. C#Web网站的创建

    一.CS与BS的区别 CS软件:需要在客户端安装软件. BS软件:只需要浏览器就能运行,Web网站就是BS软件. 创建过程: 1.文件新建---新建网站----空白网站 2.右击网站项目---添加网页 ...

  8. F - No Link, Cut Tree! Gym - 101484F

    Marge is already preparing for Christmas and bought a beautiful tree, decorated with shiny ornaments ...

  9. Hive(二)—— 架构设计

    Hive架构 Figure 1 also shows how a typical query flows through the system. 图一显示一个普通的查询是如何流经Hive系统的. Th ...

  10. moco jar包下载

    http://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/0.11.0/ 选择moco-runner-0.11.0-standalo ...