当前位置: 技术问答>java相关
在Java中怎样实现GBK内码到Unicode的转换
来源: 互联网 发布时间:2015-08-05
本文导语: 如“中”GBK为D6 D0 而unicode为4E 2D. 谢谢 | public static String UnicodeToGBK(String s){ try{ String newstring=null; newstring=new String(s.getBytes("ISO8859_1"),"GBK"); return newstring; } catch(Unsupp...
如“中”GBK为D6 D0
而unicode为4E 2D.
谢谢
而unicode为4E 2D.
谢谢
|
public static String UnicodeToGBK(String s){
try{
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"GBK");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
public static String GBKToUnicode(String s){
try{
String newstring=null;
newstring=new String(s.getBytes("GBK"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
try{
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"GBK");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
public static String GBKToUnicode(String s){
try{
String newstring=null;
newstring=new String(s.getBytes("GBK"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}