private double GetConvertedCurrencyValue(string inputCurrency, string outputCurrency, double value) { string request = String.Format("http://www.xe.com/ucc/convert.cgi?Amount={0}&From={1}&To={2}", value, inputCurrency, outputCurrency); System.Net.WebClient wc = new System.Net.WebClient(); string apiResponse = wc.DownloadString(request); // This is a blocking operation. wc.Dispose(); /* Formatting */ // Typical response: "XE.com: curr1 to curr2 rate: x curr1 = y curr2" // The first part, up until "x curr1" is basically a constant string header = String.Format("XE.com: {0} to {1} rate:", inputCurrency, outputCurrency); // Removing the header // The response now looks like this: x curr1 = y curr2 apiResponse = apiResponse.Replace(header, ""); // Let's split the response at '=', to retrieve the right part string outValue = apiResponse.Split('=')[1]; // Getting rid of the 'curr2' part outValue = outValue.Replace(outputCurrency, ""); return Double.Parse(outValue, System.Globalization.CultureInfo.InvariantCulture); }
string header = String.Format("XE.com: {0} to {2} rate:", inputCurrency, outputCurrency);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)