1

I have a string url like http://google.com. I need to remove 'http://' from the URL. I have tried the method .replace("http://",""), but it is not working.

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
Nidheesh
  • 4,390
  • 29
  • 87
  • 150

2 Answers2

4

Try:

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

As replace returns the replaced string

BobTheBuilder
  • 18,858
  • 6
  • 40
  • 61
4

You need to do like following.String is immutable class.replace will return you new String object.

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

Refer String is immutable. What exactly is the meaning?

Community
  • 1
  • 1
Jaydeep Rajput
  • 3,605
  • 17
  • 35