Advertisement
YavorGrancharov

test_url

Oct 28th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace test_url
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             //Test url:
  12.             //https://www.pornhub.com/view_video.php?viewkey=608247796
  13.  
  14.             string input = Console.ReadLine();
  15.  
  16.             Dictionary<string, string> data = new Dictionary<string, string>();
  17.  
  18.             string[] tokens = input.Split(new string[] { ":", "www.", "/" },
  19.                 StringSplitOptions.RemoveEmptyEntries);
  20.  
  21.             string protocol = tokens[0];
  22.             string host = tokens[1];
  23.             string presource = input
  24.                 .Substring(input.IndexOf("/") + host.Length - 1, input.Length - (protocol.Length + host.Length));
  25.  
  26.             string resource = string.Join(string.Empty, presource.Skip(3));
  27.  
  28.             data.Add("Protocol:", protocol);
  29.             data.Add("Host:", host);
  30.             data.Add("Resource:", resource);
  31.  
  32.             Console.WriteLine();
  33.  
  34.             foreach (var entry in data)
  35.             {
  36.                 Console.WriteLine("{0} {1}", entry.Key, entry.Value);
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement