Topic: chinese conversion to unicode?

  Print this page

1.chinese conversion to unicode? Copy to clipboard
Posted by: ringayumi
Posted on: 2003-10-31 00:47

How to do chinese conversion to unicode?

for example:
System.out.println(....);

console display:
\u8293

2.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: gouride
Posted on: 2003-10-31 09:26


String encoding = "gb2312";
String str = "";
byte b[] = str.getBytes(encoding);
ByteToCharConverter converter = ByteToCharConverter.getConverter(encoding);
char[] c = converter.convertAll(b);
for (int i = 0; i < c.length; i ++) {
System.out.println(Integer.toHexString(c[i]));
}

3.Re:chinese conversion to unicode? [Re: gouride] Copy to clipboard
Posted by: ringayumi
Posted on: 2003-10-31 10:09

Where is the ByteToCharConverter class?

4.Re:chinese conversion to unicode? [Re: gouride] Copy to clipboard
Posted by: nothing
Posted on: 2003-10-31 11:01

gouride wrote:

String encoding = "gb2312";
String str = "";
byte b[] = str.getBytes(encoding);
ByteToCharConverter converter = ByteToCharConverter.getConverter(encoding);
..................



ByteToCharConverter ??
java.io.ByteToCharConverter ??
Java Development Kit 1.1 Beta ??

5.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: jeez
Posted on: 2003-11-01 23:13

String encoding = "gb2312";
String str = "";
String outStr = new String( str.getBytes(encoding) );

6.Re:chinese conversion to unicode? [Re: jeez] Copy to clipboard
Posted by: ringayumi
Posted on: 2003-11-02 21:48

about Byte class of J2SDK 1.4 API below:
Byte
ByteArrayInputStream
ByteArrayOutputStream
ByteBuffer
ByteChannel
ByteHolder
ByteLookupTable
ByteOrder

no ByteToCharConverter!!!!!

7.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: gouride
Posted on: 2003-11-03 09:59

sun.io.ByteToCharConverter

8.Re:chinese conversion to unicode? [Re: gouride] Copy to clipboard
Posted by: ringayumi
Posted on: 2003-11-03 10:52

Thanks , I found it!!

But , I have another solution.

String str = "您";
char[] c = str.toCharArray();
for (int i = 0; i < c.length; i ++)
{
  System.out.println(Integer.toHexString(c[i]));
}

9.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: ringayumi
Posted on: 2003-11-03 10:55

But , how to use the unicode conversion to chinese?

for example:

\u1234 <== it's a String

How to use the String conversion to char type now?

10.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: sc33
Posted on: 2003-11-03 11:59

最简单的方法是:
System.out.println("\u1234");

11.Re:chinese conversion to unicode? [Re: sc33] Copy to clipboard
Posted by: ringayumi
Posted on: 2003-11-03 13:49

for example:

String a = "\\u1234";

System.out.printlnAngel;

console print:
\u1234

How to use unicode conversion to chinese?

12.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: dog72
Posted on: 2003-11-03 13:53

不要用未公开的API丫!

13.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: ringayumi
Posted on: 2003-11-03 16:58

ringayumi wrote:
for example:

String a = "\\u1234";

System.out.printlnAngel;

console print:
\u1234

How to use unicode conversion to chinese?


Because I would like to process the dynamic unicode!

14.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: gouride
Posted on: 2003-11-04 08:56

CharToByteConverter con = CharToByteConverter.getConverter("GB2312");
char[] ch = {'\u4f60', '\u597d'};
byte[] b = con.convertAll(ch);
String str = new String(b, "GB2312");
System.out.println(str);

15.Re:chinese conversion to unicode? [Re: gouride] Copy to clipboard
Posted by: ringayumi
Posted on: 2003-11-04 09:32

You are using the char array.

But , i would like to process the String!!

String k = new String("\\u1234");

How to conversion to chinese above?

16.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: gouride
Posted on: 2003-11-04 12:46

I think you have to convert string to char array by yourself, no api available.

17.Re:chinese conversion to unicode? [Re: gouride] Copy to clipboard
Posted by: ringayumi
Posted on: 2003-11-04 13:22

for example:

String str = "\\u1234";
char[] c = str.toCharArray();
for (int i = 0; i < c.length; i ++)
{
  System.out.println((c[i]));
}

the console print:
\
u
1
2
3
4

But , i want to print a chinese !!
Have any solution?

18.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: gouride
Posted on: 2003-11-04 15:17

No, not that way. I will show you a little routine, it's input parameter takes the format "\\u4f60\\u597d";


public static char[] toCharArray(String str) {
  int len = str.length() / 6;
  char ch[] = new char[len];
  
  for(int i=0;i<len;i++) {
    String chs = str.substring(i*6+2, i*6+6);
    int ii = Integer.parseInt(chs, 16);      
    ch[i] = (char)ii;
  }
  return ch;
}

19.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: ringayumi
Posted on: 2003-11-05 00:09

Thank you very much! gouride!!^_^

This is a nice solution.

You are very strong programmer!!

20.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: nothing
Posted on: 2003-11-05 00:13

好!

21.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: jeffrey
Posted on: 2003-11-06 00:41

想要查看被转换后的unicode正确结果,可以通过JDK自带的小应用程序native2ascii.exe来验证:

用法说明:
native2ascii [-reverse] [-encoding encoding] [inputfile [outputfile]]

例:
native2ascii -encoding iso-8859-1 test.txt

其中,test.txt包含汉字 "你好"

输出结果:
\u00c4\u00e3\u00ba\u00c3

22.Re:chinese conversion to unicode? [Re: ringayumi] Copy to clipboard
Posted by: altonpeng
Posted on: 2003-11-06 13:11

native2ascii 是资源实现本地化的一个命令,用在国际化语言方面


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923