Tuesday, June 5, 2012

How to Split the the Domain from a URL ...asp .net


How to Split the the Domain from a URL:

Server Side   aspx.cs  Code

string url = "http://www.google.com";
 Uri uri = new Uri(url);
 string domain1 = uri.Host;   // Output will be :   www.google.com

======
  string findsub = "www.";
                int k = domain1.IndexOf(findsub);    // Output will be :   www
                if (k >= 0)
                {
                    domain = domain1.Substring(k + findsub.Length);       // Output will be :  google.com
                }
                else
                {
                    domain = domain1;           // Output will be :  google.com
                }

No comments:

Post a Comment