Click here to Skip to main content
15,919,028 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
private double GetConvertedCurrencyValue(string inputCurrency, string outputCurrency, double value)
       string request = String.Format("{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.

       /* Formatting */
       // Typical response: " curr1 to curr2 rate: x curr1 = y curr2"
       // The first part, up until "x curr1" is basically a constant

       string header = String.Format(" {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);

it gives an below error in last line .please reply immediately......

Input string was not in a correct format.
Updated 15-Apr-14 20:26pm

1 solution

string header = String.Format(" {0} to {2} rate:", inputCurrency, outputCurrency);

try {1}

Is that immediate enough?
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900