unicode编码与解码
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编码与解码的更多相关文章
- PHP中对汉字进行UNICODE编码和解码的实现
<?php /** PHP中对汉字进行UNICODE编码和解码的实现 **/ class Helper_Tool{ //php中的unicode编码转中文 static function uni ...
- C# Unicode编码与解码方法
public static class ExtentMethod { public static string ToUnicodeString(this string str) { StringBui ...
- java基础52 编码与解码
1.解码与编码的含义 编码:把看得懂的字符变成看不懂的码值,这个过程就叫编码 解码:根据码值查到相对应的字符,我们把这个过程就叫解码 注意:编码与解码时,我们一般使用统一的码表,否则非常容易出现 ...
- Day 19:Properties配置文件类、打印流(printStream) 、 编码与解码
Properties(配置文件类): 主要用于生产配置文件与读取配置文件的信息. Properties要注意的细节: 1. 如果配置文件的信息一旦使用了中文,那么在使用store方法生成配置文件的时 ...
- Unicode编码解码在线转换工具
// Unicode编码解码在线转换工具 Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standar ...
- RapidJSON 代码剖析(三):Unicode 的编码与解码
根据 RFC-7159: 8.1 Character Encoding JSON text SHALL be encoded in UTF-8, UTF-16, or UTF-32. The defa ...
- [SAP ABAP开发技术总结]字符编码与解码、Unicode
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- PHP解码unicode编码中文字符代码示例
在抓取某网站数据,结果在数据包中发现了一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......", 这其实是中文被unicode编码后了的数据,想 ...
- C# \uxxx Unicode编码解码
/// <summary> /// Unicode编码 /// </summary> /// <param name="str"></pa ...
随机推荐
- UML-领域模型-属性
1.属性预览 2.导出属性是什么? 3.属性使用什么样的数据类型? 常见的数据类型:boolean.Date.String(Text).Integer 其他常见的:SKU.枚举类型等 而在java类中 ...
- CkEditor - Custom CSS自定义样式
CkEditor是目前世界上最多人用的富文本编辑器.遇上客户提需求,要改一下编辑器的样式,那就是深入CkEditor的底层来修改源码. 修改完的样式是这样,黑边,蓝底,迷之美学.这就是男人自信的表现, ...
- 七、Shell脚本高级编程实战第七部
一.写网络服务的系统启动脚本 利用case语句开发类似系统启动rsync服务的脚本 代码: #!/bin/sah. /etc/init.d/functionspidfile="/var/ru ...
- BOM(Broswer Object Model)
BOM(Broswer Object Model) 方法: 框窗 1.警告框 window.alert("msg"); 2.确认框 window ...
- 五、linux-mysql 下mysql的管理(二)
1.插入语句: create table test( id int(4) not null auto_increment, name char(20) not null, primary ...
- [LC] 452. Minimum Number of Arrows to Burst Balloons
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- 不同SQL数据库之间表数据的实时同步-发布与订阅
https://blog.csdn.net/rand_muse/article/details/81326879 上述文章中,如果是实时同步,选择 事务发布即可 在快照代理 那里,不需要勾选 运行 ...
- 代码审计中的CSRF
0x00 背景 CSRF漏洞中文名为“跨站请求伪造”,英文别名为“one-click-attack”.从字面上我们就可以看出,这是一种劫持其他用户进行非法请求的攻击方式,主要用于越权操作,与XSS相比 ...
- python3下scrapy爬虫(第十四卷:scrapy+scrapy_redis+scrapyd打造分布式爬虫之执行)
现在我们现在一个分机上引入一个SCRAPY的爬虫项目,要求数据存储在MONGODB中 现在我们需要在SETTING.PY设置我们的爬虫文件 再添加PIPELINE 注释掉的原因是爬虫执行完后,和本地存 ...
- android完整智能家居、备忘录、蓝牙配对、3D动画库、购物车页面、版本更新自动安装等源码
Android精选源码 app 版本更新.下载完毕自动自动安装 android指针式分数仪表盘 ANdroid蓝牙设备搜索.配对 Android 图片水印框架,支持隐形数字水印 android3D旋转 ...