S
Sender
I have string of Chinese characters encoded with "big5". I convert it to
unicode and use a printBytes method to display the hex value to System.out.
Here is the coding:
String cname ...... //this is the big5 string
if (cname != null) {
printBytes(cname.getBytes(), "CName ");
ch_name = new String(cname.getBytes(), "BIG5");
printBytes(ch_name.getBytes(), "ch_name ");
String bb = new String(ch_name.getBytes("BIG5"));
printBytes(bb.getBytes(), "bb ");
}
public static void printBytes(byte[] array, String name) {
System.out.print(name + " = ");
for (int k = 0; k < array.length; k++) {
System.out.print("0x" + Common.byteToHex(array[k]) + " ");
}
System.out.println();
}
And here is the output of printBytes:
CName = 0xb5 0xd8 0xb1 0xe1 0xa4 0xa4 0xb0 0xea
ch_name = 0x3f 0x3f 0x3f 0x3f
bb = 0xb5 0xd8 0xb1 0xe1 0xa4 0xa4 0xb0 0xea
As you can see, ch_name became "????". But the last 2 lines of code can
convert it back to the original big5 string. Why? I've tried to insert some
awt frame displaying code inbetween (the ShowString from Sun) and found that
ch_name can display the Chinese correctly. Why? In fact, what I wanted to do
is to convert the big5 string to unicode and store it as a varchar column in
MySql. While I can store the ch_name, it only stored as "????" and
retrieving it cannot be displayed in ShowString correctly. In other words,
if convert-and-display, it works, if convert-store-display, it doesn't work.
Any help?
unicode and use a printBytes method to display the hex value to System.out.
Here is the coding:
String cname ...... //this is the big5 string
if (cname != null) {
printBytes(cname.getBytes(), "CName ");
ch_name = new String(cname.getBytes(), "BIG5");
printBytes(ch_name.getBytes(), "ch_name ");
String bb = new String(ch_name.getBytes("BIG5"));
printBytes(bb.getBytes(), "bb ");
}
public static void printBytes(byte[] array, String name) {
System.out.print(name + " = ");
for (int k = 0; k < array.length; k++) {
System.out.print("0x" + Common.byteToHex(array[k]) + " ");
}
System.out.println();
}
And here is the output of printBytes:
CName = 0xb5 0xd8 0xb1 0xe1 0xa4 0xa4 0xb0 0xea
ch_name = 0x3f 0x3f 0x3f 0x3f
bb = 0xb5 0xd8 0xb1 0xe1 0xa4 0xa4 0xb0 0xea
As you can see, ch_name became "????". But the last 2 lines of code can
convert it back to the original big5 string. Why? I've tried to insert some
awt frame displaying code inbetween (the ShowString from Sun) and found that
ch_name can display the Chinese correctly. Why? In fact, what I wanted to do
is to convert the big5 string to unicode and store it as a varchar column in
MySql. While I can store the ch_name, it only stored as "????" and
retrieving it cannot be displayed in ShowString correctly. In other words,
if convert-and-display, it works, if convert-store-display, it doesn't work.
Any help?