Advertisement
stanevplamen

02.8a.08..ParseURLClass

Jun 14th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Reflection.Emit;
  3. using System.Text.RegularExpressions;
  4.  
  5. class ParseURLClass
  6. {
  7.     static void Main()
  8.     {
  9.         string fileName = @"http://www.devbg.org/forum/index.php ";
  10.  
  11.         Uri uri = new Uri(fileName);
  12.         Console.WriteLine(uri.AbsoluteUri);
  13.         Console.WriteLine(uri.Scheme);
  14.         Console.WriteLine(uri.Authority);
  15.         Console.WriteLine(uri.PathAndQuery);
  16.         Console.WriteLine();
  17.         Console.WriteLine("//========================");
  18.         Console.WriteLine("//========================");
  19.         Console.WriteLine();
  20.         string url = "http://www.cambiaresearch.com"
  21.            + "/Cambia3/snippets/csharp/regex/uri_regex.aspx?id=17#authority";
  22.         Console.WriteLine(url);
  23.         string regexPattern = @"^(?<s1>(?<s0>[^:/\?#]+):)?(?<a1>"
  24.            + @"//(?<a0>[^/\?#]*))?(?<p0>[^\?#]*)"
  25.            + @"(?<q1>\?(?<q0>[^#]*))?"
  26.            + @"(?<f1>#(?<f0>.*))?";
  27.  
  28.         Regex re = new Regex(regexPattern, RegexOptions.ExplicitCapture);
  29.         Match m = re.Match(url);
  30.  
  31.         if (m.Success)
  32.         {
  33.             GroupCollection gr = m.Groups;
  34.             Console.WriteLine("{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}", gr["s0"], gr["s1"], gr["a0"], gr["a1"], gr["p0"], gr["q1"], gr["f0"], gr["f1"]);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement