consider the url is
http://www.google.com/a/b/myendpoint
All I want is the following
http://www.google.com/a/b/
One approach is to split the String url and join all the components except last one.
I am thinking if there could be a better way?
You can use lastIndexOf()
:
url.substring(0, url.lastIndexOf('/') + 1)
String url = "http://www.google.com/a/b/myendpoint";
System.out.println(url.substring(0, url.lastIndexOf('/') + 1));
http://www.google.com/a/b/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With