Hello all,
I want to convert exchange rage from one currency to another, Following is the code
string txt;
string url = "http://www.google.com/finance/converter?a=1&from=USD&to=INR";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
WebResponse response = request.GetResponse();
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
txt = reader.ReadToEnd();
}
the out put of "txt" variable is in the form of full html page. following is the part of html output
<div id=currency_converter_result>1 USD = <span class=bld>62.9100 INR</span>
<input type=submit value="Convert">
</div>
Previously I have tried following code but not success ...
string response = web.DownloadString(url);
Regex regex = new Regex("rhs: \\\"(\\d*.\\d*)");
Match match = regex.Match(response);
rate = System.Convert.ToDecimal(match.Groups[1].Value);
Previously my code was working, but after the change of google API my code not worked ....
I am searching the solution as
1. I can serialize my currency Rate in to json format
2. I can use any API like google api , yahoo api , etc from the web.config file and my code will work for all.
Please help me and suggest me with perfect solution.
I am writing my app. in MVC 4 , with C#.
Thanks in advance
With Regards,
Manoj