Advertisement
VladoG

[PrgFundament] (Strings) - 05. URL Parser

Jun 9th, 2016
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.URL_Parser
  8.     {
  9.     class URLParser
  10.         {
  11.         static void Main(string[] args)
  12.             {
  13.             char[] separators = { ':', '/' };
  14.             string inputStr = Console.ReadLine();
  15.             string[] fullPath = inputStr.Split(separators, StringSplitOptions.RemoveEmptyEntries);
  16.             string protocol = "";
  17.             string server = "";
  18.             int pathPOS = 2;
  19.             List<string> resource = new List<string>();
  20.  
  21.             if (inputStr.Contains("://"))
  22.                 {
  23.                 protocol = fullPath[0];
  24.                 Console.WriteLine($"[protocol] = \"{protocol}\"");
  25.                 server = fullPath[1];
  26.                 }
  27.             else
  28.                 {
  29.                 Console.WriteLine($"[protocol] = \"{protocol}\"");
  30.                 server = fullPath[0];
  31.                 pathPOS = 1;
  32.                 }
  33.  
  34.             Console.WriteLine($"[server] = \"{server}\"");
  35.             Console.Write($"[resource] = \"");
  36.  
  37.             // With LIST solution
  38.             for (int i = pathPOS; i < fullPath.Length; i++)
  39.                 {
  40.                 resource.Add(fullPath[i]);
  41.                 }
  42.             Console.Write(string.Join("/", resource));
  43.  
  44.             ////Without LIST solution
  45.             //for (int i = pathPOS; i < fullPath.Length; i++)
  46.             //    {
  47.             //    Console.Write(fullPath[i]);
  48.             //    if (i < fullPath.Length - 1)
  49.             //        {
  50.             //        Console.Write("/");
  51.             //        }
  52.             //    }
  53.  
  54.             Console.WriteLine("\"");
  55.  
  56.             }
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement