Advertisement
Jong

Get Dollar gate sample - FXP

Jan 9th, 2012
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1.     class Program
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             double d = GetDollarGate();
  6.             Console.WriteLine("One dollar is " + d + " NIS.");
  7.  
  8.         }
  9.         static double GetDollarGate()
  10.         {
  11.             WebRequest request = WebRequest.Create("http://www.dollargate.net/");
  12.             WebResponse response = request.GetResponse();
  13.             Stream stream = response.GetResponseStream();
  14.             string html = null;
  15.             using (StreamReader reader = new StreamReader(stream))
  16.             {
  17.                 html = reader.ReadToEnd();
  18.             }
  19.             stream.Close();
  20.  
  21.             //And now, the HTML tag containing the dollar info is <div id="dollar_2">...</div>
  22.             int tagStart = html.IndexOf("<div id=\"dollar_2\">");
  23.             int tagEnd = html.IndexOf("</div>", tagStart);
  24.             int tagDeclarationLength = "<div id=\"dollar_2\">".Length;
  25.             int tagLength = tagEnd - (tagStart + tagDeclarationLength);
  26.             string dollar = html.Substring(tagStart + tagDeclarationLength, tagLength);
  27.             return double.Parse(dollar);
  28.         }
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement