Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program that parses an URL address given in the format:
- // [protocol]://[server]/[resource]
- // 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:
- // [protocol] = "http"
- // [server] = "www.devbg.org"
- // [resource] = "/forum/index.php"
- using System;
- class ParseURLAddress
- {
- static void Main()
- {
- string sURL = "http://www.devbg.org/forum/index.php";
- int nIdx1 = sURL.IndexOf("://");
- string sSrvAndResource = sURL.Substring(nIdx1 + 3); //take only server and resource from URL
- int nIdx2 = sSrvAndResource.IndexOf("/");
- Console.WriteLine("[protocol] = \"{0}\"", sURL.Substring(0, nIdx1));
- Console.WriteLine("[server] = \"{0}\"", sSrvAndResource.Substring(0, nIdx2));
- Console.WriteLine("[resource] = \"{0}\"", sSrvAndResource.Substring(sSrvAndResource.IndexOf("/")));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement