Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. private static string CurrencyConvert(decimal amount, string fromCurrency, string toCurrency)
  2. {
  3. try
  4. {
  5. //Grab your values and build your Web Request to the API
  6. string apiURL = String.Format("https://www.google.com/finance/converter?a={0}&from={1}&to={2}&meta={3}", amount, fromCurrency, toCurrency, Guid.NewGuid().ToString());
  7.  
  8. //Make your Web Request and grab the results
  9. var request = WebRequest.Create(apiURL);
  10.  
  11. //Get the Response
  12. StreamReader streamReader = new StreamReader(request.GetResponse().GetResponseStream(), System.Text.Encoding.ASCII);
  13.  
  14. //Grab your converted value (ie 2.45 USD)
  15. String temp = streamReader.ReadToEnd().ToString();
  16. int pFrom = temp.IndexOf("<span class=bld>") + ("<span class=bld>").Length;
  17. int pTo = temp.LastIndexOf("</span>");
  18.  
  19. System.Windows.MessageBox.Show(pFrom.ToString() + " " + pTo.ToString());
  20. String result = temp.Substring(pFrom, pTo - pFrom);
  21.  
  22. // string result = Regex.Matches(streamReader.ReadToEnd(), "<span class="?bld"?>([^<]+)</span>")[0].Groups[1].Value;
  23.  
  24. //Get the Result
  25. return result;
  26. }
  27. catch(Exception ex )
  28. {
  29. return "";
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement