1

我有一个像http://google.com. 我需要'http://'从 URL 中删除。我已经尝试过该方法.replace("http://",""),但它不起作用。

Web web = org.getWeb();
webUrl = web.getUrl();
out.println("webUrl :"+webUrl );  // here it prints:: http://google.com
webUrl.replace("http://","");
out.println("webUrl :"+webUrl );  // here also it prints:: http://google.com
4

2 回答 2

4

尝试:

webUrl = webUrl.replace("http://","");

替换返回被替换的字符串

于 2013-04-08T07:00:07.010 回答
4

您需要执行以下操作。String 是不可变的类。replace 将返回您新的 String 对象。

webUrl = webUrl.replace("http://","");

引用字符串是不可变的。究竟是什么意思?

于 2013-04-08T07:01:41.510 回答