Advertisement
YavorGrancharov

test_url_2_fixed

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