今天在CSDN论坛上无意中找到一个帖子,需要从百度的URL中分析出来关键字。保存下来,以备今后使用。
String url_0 = "%259d%2571%2566%259e%2554%2576%25a0%2560%2574%259e%2543%2561";
//1 去掉 25
String url_1 = "%9d%71%66%9e%54%76%a0%60%74%9e%43%61";
String[] url_2 = url_1.split("%");
StringBuilder url_3 = new StringBuilder();
for(int i=1;i<url_2.length;i++){
String str = url_2[i];
String res = Integer.valueOf(str,16).toString();
int intRes = Integer.parseInt(res);
intRes = intRes+256;
intRes = intRes-201;
String str_16 = Integer.toHexString(intRes+16);//注意这里 比 网上的 多加 了一个 16
url_3.append("%"+str_16);
}
System.out.println(url_3.toString());
String strRes = URLDecoder.decode(url_3.toString(),"UTF-8");
System.out.println(strRes);
以上出自csdn论坛: http://bbs.csdn.net/topics/390787490
顺便google的也贴出来
public void testEncode() throws UnsupportedEncodingException {
// 从google拿出来的关键字
String googleUrl = "%E5%90%91%E6%97%A5%E8%91%B5%E4%BF%9D%E9%99%A9%E7%BD%91";
System.out.println(URLDecoder.decode(googleUrl, "utf8"));
}
以上出自ITEYE: http://oyhk.iteye.com/blog/1759469