gpt4 book ai didi

java - 如何使用 JSOUP 或 Coldfusion 从 URL 中删除查询字符串和哈希值?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:01 25 4
gpt4 key购买 nike

最佳答案

我创建了一个辅助方法 processURL(),它接受一个 URL 并返回一个包含查询标记 (?) 或井号 (#):

String processURL(String theURL) {
int endPos;
if (theURL.indexOf("?") > 0) {
endPos = theURL.indexOf("?");
} else if (theURL.indexOf("#") > 0) {
endPos = theURL.indexOf("#");
} else {
endPos = theURL.length();
}

return theURL.substring(0, endPos);
}

String urlOne = "http://stackoverflow.com/questions/tagged/jav?#sort=featured&pageSize=50";
String urlTwo = "http://stackoverflow.com/questions/tagged/java#comments";

System.out.println(processURL(urlOne));
System.out.println(processURL(urlTwo));

输出:

http://stackoverflow.com/questions/tagged/java
http://stackoverflow.com/questions/tagged/java

关于java - 如何使用 JSOUP 或 Coldfusion 从 URL 中删除查询字符串和哈希值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33471700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com