5D艺术网首页
商城
|
资讯
|
作品
|
博客
|
教程
|
论坛
登录
注册
加为好友
发短消息
来自:不正常人类研究中心
性别:先生
最后登录:2008-11-03
http://samuel.5d.cn/
我是来买馒头的~
首页
|
新闻
|
话题
|
博客
|
相册
|
艺术作品
|
社交关系
|
留言板
|
社交圈
2005/10/19 | JAVA中将汉字转换为Unicode和Utf-8的两个函数
类别(Programme)
|
评论
(4)
|
阅读(3144)
|
发表于 13:45
static public String StringToUnicode(String text) {
String result = "";
int input;
StringReader isr;
try {
isr = new StringReader(new String(text.getBytes(), "GBK"));
}
catch (UnsupportedEncodingException e) {
return "-1";
}
try {
while ( (input = isr.read()) != -1) {
result = result + "&#x" + Integer.toHexString(input) + ";";
}
}
catch (IOException e) {
return "-2";
}
isr.close();
return result;
}
public static String gb2utf(String inStr) {
char temChr;
int ascInt;
int i;
String result = new String("");
if (inStr == null) {
inStr = "";
}
for (i = 0; i < inStr.length(); i++) {
temChr = inStr.charAt(i);
ascInt = temChr + 0;
System.out.println(ascInt);
System.out.println(Integer.toBinaryString(ascInt));
result = result + "&#x" + Integer.toHexString(ascInt) + ";";
}
return result;
}
0
评论
Comments
日志分类
首页
[50]
MyBlog
[11]
WebService
[3]
Programme
[19]
Pastime
[17]