Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Razor 货币兑换问题屡禁不止_Razor_C# 4.0_Model View Controller - Fatal编程技术网

Razor 货币兑换问题屡禁不止

Razor 货币兑换问题屡禁不止,razor,c#-4.0,model-view-controller,Razor,C# 4.0,Model View Controller,我有一门课,现在可以帮助将美元转换成印度卢比,现在给出的错误是: 指定的参数超出了有效值的范围 在这一行代码行: var result = Regex.Matches(streamReader.ReadToEnd(), "<span class=\"?bld\"?>([^<]+)</span>")[0].Groups[1] var result=Regex.Matches(streamReader.ReadToEnd(),”([^我建议将正则表达式与匹配解析分开,

我有一门课,现在可以帮助将美元转换成印度卢比,现在给出的错误是:

指定的参数超出了有效值的范围

在这一行代码行:

var result = Regex.Matches(streamReader.ReadToEnd(), "<span class=\"?bld\"?>([^<]+)</span>")[0].Groups[1]

var result=Regex.Matches(streamReader.ReadToEnd(),”([^我建议将正则表达式与匹配解析分开,您将看到错误。类似于:var Matches=Regex.Matches(streamReader.ReadToEnd(),input);if(Matches.Count()>0){var match=Matches[0];if(match.Groups.Count()>=2){var group=match.Groups[1]}关于APIurl有错误,但我没有得到ITI的修复Api Url。如果您按照我的建议使用变量分割逻辑,您将看到确切的问题。我认为web请求带来的响应内容与您的正则表达式不匹配。
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", ""));
}