using System; using System.Linq; using System.IO; public class Test { public static void Main() { String[]uris = new[]{ "http://s...content-available-to-author-only...1.org/info.php","http://s...content-available-to-author-only...2.com/info/index.php","http://s...content-available-to-author-only...3.edu/", "http://s...content-available-to-author-only...3.edu/", "no uri", "" }; var result = uris.Where(u => Uri.IsWellFormedUriString(u, UriKind.Absolute)) .Select(u => { var p = new Uri(u).ToString(); return p.Substring(0, p.LastIndexOf('/') +1); }) .Distinct() .ToArray(); Console.Write(String.Join(Environment.NewLine,result)); } }