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 ...
随机推荐
- java依赖包问题排查
使用算法 breeze.optimize.LBFGSB,出现如下问题: 看到github上一个issue的解决方法是使用最新版本的 org.scalanlp:breeze_2.11:1.0-RC2, ...
- flutter实现promise中resolve(RxJava中emiter.onSucess("result"))功能
BehaviorSubject openCameraController = BehaviorSubject(); BridgeChannel _openCamera() { print('- - - ...
- Codeforces 1294C - Product of Three Numbers
题目大意: 给定一个n,问是否存在3个互不相同的,大于等于2的整数,满足a*b*c=n 解题思路: 可以把abc其中任意两个看作一个整体,例如a*b=d,那么可以发现d*c=n 所以d和c是n的因子 ...
- JavaEE--分布式对象
参考:http://blog.csdn.net/smcwwh/article/details/7080997 1.客户与服务器的角色 所有分布式编程技术的基本思想都很简单:客户计算机产生一个请求,然后 ...
- Python 进行 OCR识别 -- pytesseract库
pip install pytesseract 报错:tesseract is not installed or it's not in your path 下载安装 Tesseract-OCR ht ...
- TextBox换行C#文本框换行.net文本框换行textarea换行
在TextBox中输入的内容,显示的时候如果用lable显示,无法换行 可以使用TextBox输入,然后也使用TextBox 显示,这样换行输入的内容,显示的时候也可以换行.显示的时候可以设置一下控件 ...
- 2020 CCPC Wannafly Winter Camp Day2-K-破忒头的匿名信
题目传送门 sol:先通过AC自动机构建字典,用$dp[i]$表示长串前$i$位的最小代价,若有一个单词$s$是长串的前$i$项的后缀,那么可以用$dp[i - len(s)] + val(s)$转移 ...
- [LC] 299. Bulls and Cows
Example 1: Input: secret = "1807", guess = "7810" Output: "1A3B" Expla ...
- crm项目-需求分析
############### crm需求分析 ############### 讲师和学生:1,批量生成上课记录,2,考勤点名,3,录入成绩,4,显示成绩5,上传作业,os模块,6,下载成绩, ...
- rest framework-视图和路由-长期维护
############### 三种视图 ############### # 第一种方法:使用mixins # class AuthorView(mixins.ListModelMixin, ...