I have the following URL
I want to break this into below URL-
www.androidexample.com
How can write code for this?
I have the following URL
I want to break this into below URL-
www.androidexample.com
How can write code for this?
Use:
String uriStr = "http://androidexample.com/Create_A_Simple_Listview_-_Android_Example/index.php?view=article_discription&aid=65&aaid=90";
String host = new URI(uriStr).getHost();
URI uri = new URI("http://androidexample.com/Create_A_Simple_Listview_-_Android_Example/index.php?view=article_discription&aid=65&aaid=90");
System.out.println("URI : " + uri);
System.out.println(uri.getHost());
You can look for the //
and for the first /
in the url.
e.g.
int slashslash = url.indexOf("//") + 2;
domain = url.substring(slashslash, url.indexOf('/', slashslash));
It was answered here: What is the fastest way to get the domain/host name from a URL?
You have to get domain name of particular URL. just pass your URL in below code you can get domain or sub URL.
String url="http://androidexample.com/Create_A_Simple_Listview_-_Android_Example/index.php?view=article_discription&aid=65&aaid=90";
String subUrl = getDomainName(url);
public static String getDomainName(String url) throws URISyntaxException {
URI uri = new URI(url);
String domain = uri.getHost();
return domain.startsWith("www.") ? domain.substring(4) : domain;
}