我有类帮助将usd转换为inr现在正在给出错误,这就是:
指定的参数超出了有效值的范围。
在此行代码行中:
var result = Regex.Matches(streamReader.ReadToEnd(), "<span class=\"?bld\"?>([^<]+)</span>")[0].Groups[1]
这是一个完整的课程:
public static decimal CurrencyConvert(decimal amount, string fromCurrency, string toCurrency)
{
//Grab your values and build your Web Request to the API
string apiURL = String.Format("http://finance.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
var streamReader = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.ASCII);
//Grab your converted value (ie 2.45 USD)
var streamData = streamReader.ReadToEnd();
var result = Regex.Matches(streamData, "<span class=\"?bld\"?>([^<]+)</span>")[0].Groups[1].Value;
//Get the Result
return Convert.ToDecimal(result.Replace(" INR", ""));
}