-
Notifications
You must be signed in to change notification settings - Fork 4
/
ExtractUrl.cs
35 lines (31 loc) · 1.14 KB
/
ExtractUrl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class ExtractUrl
{
static void Main(string[] args)
{
Console.Write("URL:");
string url = Console.ReadLine();
int indexProtocol = url.IndexOf("://");
string protocol = url.Substring(0, indexProtocol);
int indexServer = url.IndexOf("/", indexProtocol + 3);
int serverLength = (indexServer - 1) - (indexProtocol + 2);
string server = url.Substring(indexProtocol + 3, serverLength);
string resource = url.Substring(indexServer);
Console.WriteLine("[protocol] = " + protocol);
Console.WriteLine("[server] = " + server);
Console.WriteLine("[resource] = " + resource);
}
}