在Java中做一个好的库来查询string操作

我需要在Java中做一些非常简单的URL操作。 就像在查询中获取参数的值,或更新它,…我期待在commons-lang包中find一个简单的实用程序类,但是没有。 我知道这是一个简单的问题,但是如果已经写了一些东西,为什么又要这样呢? 你知道吗?

我想至less有以下function:

String myUrl = "http://www.example.com/test.html?toto=1&titi=2"; // get the value of a parameter String parameterValue = UrlUtils.getParameterValue(myUrl, "toto"); Assert.equals(parameterValue, "1"); // update a parameter String newUrl = UrlUtils.updateParameter(myUrl, "toto", 3); parameterValue = UrlUtils.getParameterValue(myUrl, "toto"); Assert.equals(parameterValue, "3"); 

理想情况下,它将处理所有与编码相关的问题,并使用java.net.Url以及Strings。

谢谢你的帮助 !

我想你想要的是一个查询stringparsing器而不是一个url操纵器,这里是一个: http : //ostermiller.org/utils/CGIParser.java.html

Apache的httpcomponents库有一个URL解码器: http : //hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/utils/URLEncodedUtils.html

Httpcomponents是commons http客户端的inheritance者。

确实已经发布了一个高效的查询string和数字parsingJava库:

http://engineering.indeed.com/blog/2014/02/efficient-query-string-parsing-util-urlparsing/

https://github.com/indeedeng/util/tree/master/urlparsing

(免责声明:我是Indeed的工程总监。)