character encoding - How to convert UTF-8 to GBK string in java -


i retrieved html string objective site , within there section

class="f9t" name="Óû§Ãû:ôâÈ»12"  

i know it's in gbk encoding, can see ff browser display. not know how convert name string readable gbk string (such 上海 or 北京).

i using

string sname = new string(name.getbytes(), "utf-8"); byte[] gbkbytes = sname.getbytes("gb2312"); string gbkstr = new string( gbkbytes ); system.out.println(gbkstr); 

but it's not printed right in gbk text

???¡ì??:????12 

i have no clue how proceed.

assuming name.getbytes() returns gbk encoded string it's enough create string specifying encoding of array of bytes:

new string(gbkstring.getbytes(), "gbk"); 

regarding documentation name of encryption should gbk.

sample code:

string gbkstring = "Óû§Ãû:ôâÈ»12"; string utfstring = new string(gbkstring.getbytes(), "gbk"); system.out.println(utfstring); 

result (not 100% sure it's correct :) ): 脫脙禄搂脙没:么芒脠禄12


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -