Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static string CurrencyConvert(decimal amount, string fromCurrency, string toCurrency)
- {
- try
- {
- //Grab your values and build your Web Request to the API
- string apiURL = String.Format("https://www.google.com/finance/converter?a={0}&from={1}&to={2}&meta={3}", amount, fromCurrency, toCurrency, Guid.NewGuid().ToString());
- //Make your Web Request and grab the results
- var request = WebRequest.Create(apiURL);
- //Get the Response
- StreamReader streamReader = new StreamReader(request.GetResponse().GetResponseStream(), System.Text.Encoding.ASCII);
- //Grab your converted value (ie 2.45 USD)
- String temp = streamReader.ReadToEnd().ToString();
- int pFrom = temp.IndexOf("<span class=bld>") + ("<span class=bld>").Length;
- int pTo = temp.LastIndexOf("</span>");
- System.Windows.MessageBox.Show(pFrom.ToString() + " " + pTo.ToString());
- String result = temp.Substring(pFrom, pTo - pFrom);
- // string result = Regex.Matches(streamReader.ReadToEnd(), "<span class="?bld"?>([^<]+)</span>")[0].Groups[1].Value;
- //Get the Result
- return result;
- }
- catch(Exception ex )
- {
- return "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement