2014年5月15日星期四

java 16 hex turn Chinese problem ~!

UEditor has a feature called hexadecimal mode switch ;

I input Chinese characters "morning ", click on the button " to switch to hexadecimal mode " , you can view the " morning " code word corresponding to B3BF

so java through what can be translated into Chinese characters B3BF " morning " ? ? ? ?


online ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ do random assignment online post, thank you !

------ Solution ------------------------------------ --------
learning largely rely on Baidu Google 's undeniable . Baidu lot
public static String hexToStringGBK (String s) {
byte [] baKeyword = new byte [s.length () / 2];
for (int i = 0; i try {
baKeyword [i] = (byte) (0xff & Integer.parseInt (s.substring (i * 2, i * 2 + 2 ) , 16 ) ) ;
} catch (Exception e) {
e.printStackTrace ();
return "";
}
}
try {
s = new String (baKeyword, "GBK") ;/ / UTF-16le: Not
} catch (Exception e1) {
e1.printStackTrace ();
return "";
}
return s;
}
------ For reference only --------------------------------- ------
morning turn the wrong ah
------ For reference only ---------------------------------------
String s = "晨";
String to16 = "";
for (int i = 0; i < s.length(); i++) {
to16 += Integer.toHexString(s.charAt(i));
}
System.out.println(to16);
//6668


------ For reference only ---------------------------------- -----
1 floor approach is right, there is a way : String v33 = java.net.URLDecoder.decode (bf3.toString (), "gb2312"); but here on the string to be processed , adding "%" to meet the requirements decode the format . . .

The reason is not resolved soon , the reason is that only know their own fur , no in-depth study of these , thank you !

没有评论:

发表评论