\u6c49\u6c49 转换这些东西的方法和包在哪?

cb1156 2008-06-19 05:23:12
RT
我要转成中文
也要中文转成这编码 的方法,和在哪个包
最好有调用实例
...全文
229 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
cb1156 2008-06-19
  • 打赏
  • 举报
回复
原出处
http://topic.csdn.net/t/20060406/14/4667598.html
cb1156 2008-06-19
  • 打赏
  • 举报
回复


String s="中";
int chr=(char)s.charAt(0);
String result= "\\u" + Integer.toHexString(chr);


感谢LS的
已用此方法解决
没用 saveConvert
下班前结帖
你要的话
明天加100分你
我结帖之前 -_,-
cb1156 2008-06-19
  • 打赏
  • 举报
回复
请问把中文转过去的有吗?
farandfaraway 2008-06-19
  • 打赏
  • 举报
回复

public static void main(String[] args){
test t=new test();
String u="\u6c49\u6c49";
System.out.println(t.loadConvert(u));
}

/*
* Converts encoded \uxxxx to unicode chars
* and changes special saved chars to their original forms
*/
private String loadConvert(String theString) {
char aChar;
int len = theString.length();
StringBuffer outBuffer = new StringBuffer(len);

for (int x = 0; x < len;) {
aChar = theString.charAt(x++);
if (aChar == '\\') {
aChar = theString.charAt(x++);
if (aChar == 'u') {
// Read the xxxx
int value = 0;
for (int i = 0; i < 4; i++) {
aChar = theString.charAt(x++);
switch (aChar) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
value = (value << 4) + aChar - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
value = (value << 4) + 10 + aChar - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
value = (value << 4) + 10 + aChar - 'A';
break;
default:
throw new IllegalArgumentException(
"Malformed \\uxxxx encoding.");
}
}
outBuffer.append((char) value);
} else {
if (aChar == 't')
aChar = '\t';
else if (aChar == 'r')
aChar = '\r';
else if (aChar == 'n')
aChar = '\n';
else if (aChar == 'f')
aChar = '\f';
outBuffer.append(aChar);
}
} else
outBuffer.append(aChar);
}
return outBuffer.toString();
}


jdk中的代码好像是
cb1156 2008-06-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 cb1156 的回复:]
引用 4 楼 TRMeister 的回复:
自己写一个挺简单的。


咱也想啊 - -
杂吧要能写也就不麻烦各位大大了
[/Quote]
勘误
cb1156 2008-06-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 TRMeister 的回复:]
自己写一个挺简单的。
[/Quote]

咱也想啊 - -
杂吧要能写也就不麻烦各位大大了
TRMeister 2008-06-19
  • 打赏
  • 举报
回复
自己写一个挺简单的。
cb1156 2008-06-19
  • 打赏
  • 举报
回复
额.
先谢过
我去搜搜
之前连搜什么关键字都不知道 - -
laorer 2008-06-19
  • 打赏
  • 举报
回复
只知道这些是unicode编码,你查下unicode编码转换成 中文吧

62,634

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧