Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the best you can get. It's not a maintainable solution, it is not a "fast" solution. (<code>GetDomain.GetDomainFromUrl</code> should be optimized).</p> <ul> <li>Use <a href="https://stackoverflow.com/a/4983058/393487">GetDomain.GetDomainFromUrl</a></li> <li>In <code>TldPatterns.EXACT</code> add <code>"co.uk"</code> (I don't know why it doesn't exist in the first place)</li> <li>Some other minor string manipulations</li> </ul> <p>This what it should look like:</p> <pre><code>using System; using System.Collections.Generic; using System.Text.RegularExpressions; class TldPatterns { private TldPatterns() { // Prevent instantiation. } /** * If a hostname is contained in this set, it is a TLD. */ static public string[] EXACT = new string[] { "gov.uk", "mil.uk", "co.uk", //... public class Program { static void Main(string[] args) { string[] urls = new[] {"www.google.com", "http://www.google.co.uk/path1/path2 ", "http://google.co.uk/path1/path2 ", "http://google.com", "http://google.co.in"}; foreach (var item in urls) { string url = item; if (!Regex.IsMatch(item, "^\\w+://")) url = "http://" + item; var domain = GetDomain.GetDomainFromUrl(url); Console.WriteLine("Original : " + item); Console.WriteLine("URL : " + url); Console.WriteLine("Domain : " + domain); Console.WriteLine("Domain Part : " + domain.Substring(0, domain.IndexOf('.'))); Console.WriteLine(); } } } </code></pre> <p>Outputs:</p> <pre><code>Original : www.google.com URL : http://www.google.com Domain : google.com Domain Part : google Original : http://www.google.co.uk/path1/path2 URL : http://www.google.co.uk/path1/path2 Domain : google.co.uk Domain Part : google Original : http://google.co.uk/path1/path2 URL : http://google.co.uk/path1/path2 Domain : google.co.uk Domain Part : google Original : http://google.com URL : http://google.com Domain : google.com Domain Part : google Original : http://google.co.in URL : http://google.co.in Domain : google.co.in Domain Part : google </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload