- //中文的utf-8范围
- Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]");
- //找到中文url中的中文
- Matcher m = p.matcher(url);
- //依次递推,查找下一个单个文字,然后把他替换成utf-8
- while(m.find()){
- String group = m.group();
- try {
- url = url.replaceFirst(group, URLEncoder.encode(group, "utf-8"));
- } catch (Exception e) {
- // do nothing
- }
- }
怎样将Url中的中文转为为UTF-8
最新推荐文章于 2024-03-12 10:59:06 发布