Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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);
   }




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


Input string was not in a correct format.
Posted
v2

1 solution

SQL
Hi
Did you check with what error did you get .I hope you get the error message like this :


return Double.Parse(outValue, System.Globalization.CultureInfo.InvariantCulture);
from outValue if you check you will get the error message as below :
"http://www.w3.org/1999/xhtml">
<head>
<!-- WARNING: Automated extraction of rates is prohibited under the Terms of Use. -->
http://www.xe.com/errors/noautoextract.htm[^]

chk this link :

http://stackoverflow.com/questions/15105308/how-to-programmatically-extract-information-from-a-web-page-using-linux-command[^]</head>
 
Share this answer
 
v2

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