Advertisement
Guest User

Untitled

a guest
Jan 19th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. //Write a program that parses an URL address given in the format:
  2. //          [protocol]://[server]/[resource]
  3. //      and extracts from it the [protocol], [server] and [resource] elements. For example from the URL http://www.devbg.org/forum/index.php the following information should be extracted:
  4. //      [protocol] = "http"
  5. //      [server] = "www.devbg.org"
  6. //      [resource] = "/forum/index.php"
  7.  
  8. using System;
  9.  
  10. class ParseURLAddress
  11. {
  12.     static void Main()
  13.     {
  14.         string sURL = "http://www.devbg.org/forum/index.php";
  15.         int nIdx1 = sURL.IndexOf("://");
  16.         string sSrvAndResource = sURL.Substring(nIdx1 + 3);  //take only server and resource from URL
  17.         int nIdx2 = sSrvAndResource.IndexOf("/");
  18.         Console.WriteLine("[protocol] = \"{0}\"", sURL.Substring(0, nIdx1));
  19.         Console.WriteLine("[server] = \"{0}\"", sSrvAndResource.Substring(0, nIdx2));
  20.         Console.WriteLine("[resource] = \"{0}\"", sSrvAndResource.Substring(sSrvAndResource.IndexOf("/")));
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement