怎样将Url中的中文转为为UTF-8

  1. //中文的utf-8范围  
  2.         Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]");  
  3. //找到中文url中的中文  
  4.         Matcher m = p.matcher(url);  
  5. //依次递推,查找下一个单个文字,然后把他替换成utf-8  
  6.         while(m.find()){  
  7.             String group = m.group();  
  8.             try {  
  9.               url =  url.replaceFirst(group, URLEncoder.encode(group, "utf-8"));  
  10.             } catch (Exception e) {  
  11.                 // do nothing  
  12.             }  
  13.         }  

猜你喜欢

转载自blog.csdn.net/qpdb19981023/article/details/78692591
今日推荐