Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- double d = GetDollarGate();
- Console.WriteLine("One dollar is " + d + " NIS.");
- }
- static double GetDollarGate()
- {
- WebRequest request = WebRequest.Create("http://www.dollargate.net/");
- WebResponse response = request.GetResponse();
- Stream stream = response.GetResponseStream();
- string html = null;
- using (StreamReader reader = new StreamReader(stream))
- {
- html = reader.ReadToEnd();
- }
- stream.Close();
- //And now, the HTML tag containing the dollar info is <div id="dollar_2">...</div>
- int tagStart = html.IndexOf("<div id=\"dollar_2\">");
- int tagEnd = html.IndexOf("</div>", tagStart);
- int tagDeclarationLength = "<div id=\"dollar_2\">".Length;
- int tagLength = tagEnd - (tagStart + tagDeclarationLength);
- string dollar = html.Substring(tagStart + tagDeclarationLength, tagLength);
- return double.Parse(dollar);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement