How to get the GB2312 CODE from the input Chinese Character in Java

1k views Asked by At

1) http://php.weather.sina.com.cn/search.php?city=%B1%B1%BE%A9&dpc=1
2) http://php.weather.sina.com.cn/search.php?city=%C9%CF%BA%A3&dpc=1

There is little difference in the two URLs above:%B1%B1%BE%A9 VS. %C9%CF%BA%A3, actually, it was B1B1BEA9 & C9CFBAA3 (according to GB2312, B1B1 represents the Chinese word"", BEA9, "", C9CF,"", BAA3, "")

I'm trying to write a program to get the GB2312 code from the input Character, for example: input:"北京", output: B1B1BEA9.

Anybody can help? Thanks a lot !

1

There are 1 answers

0
Kent On BEST ANSWER
String s="北京";
System.out.println(URLEncoder.encode(s,"GB2312"));

this will output:

%B1%B1%BE%A9

are you looking for this?