我想解码一个网址但仅限于%编码。我想保留非%编码原样:
e.g。
url =
http%3A%2F%2Fwww.domain.com%2FNews%2Fpolitics%2FMPs%2Brisk%2Blosing%2Bparliamentary%2Bimmunity%2B%2F-%2F1064%2F1395978%2F-%2Flvylki%2F-%2Findex.html
URLDecoder.decode(url, "UTF-8") = http://www.domain.com/News/politics/MPs+risk+losing+parliamentary+immunity+/-/1064/1395978/-/lvylki/-/index.html
但是如果:
url = http://www.domain.com/News/politics/MPs+risk+losing+parliamentary+immunity+/-/1064/1395978/-/lvylki/-/index.html
URLDecoder.decode(url, "UTF-8") = http://www.domain.com/News/politics/MPs risk losing parliamentary immunity /-/1064/1395978/-/lvylki/-/index.html
我想:
URLDecoder.decode(url, "UTF-8") = http://www.domain.com/News/politics/MPs+risk+losing+parliamentary+immunity+/-/1064/1395978/-/lvylki/-/index.html
如何避免URLDecoder.decode()
解码+到“”。通常我想保留非%编码的字符串,即只转换%编码。
答案 0 :(得分:1)
URLDecoder.decode(url.replaceAll("\\+", "%2B"))