使用Google货币转换API时,输入字符串不是正确的格式错误

Sam*_*m M 5 asp.net asp.net-mvc-3

我的应用程序是在C#.Net编码的Asp.Net MVC3中.我使用谷歌货币转换API来获得转换.

Google货币转换API 我将From CurrencyTo Currency值以及金额传递给我的Controller.下面是我的C#代码.

    WebClient web = new WebClient();
    string url = string.Format("http://www.google.com/ig/calculator?hl=en&q={2}{0}%3D%3F{1}", CurrenctCurr.ToUpper(), DestinationCurr.ToUpper(), TotCurrentPay);
    string response = web.DownloadString(url);
    Regex regex = new Regex("rhs: \\\"(\\d*.\\d*)");
    Match match = regex.Match(response);
    decimal rate = Convert.ToDecimal(match.Groups[1].Value);
Run Code Online (Sandbox Code Playgroud)

我在网上收到错误

decimal rate = Convert.ToDecimal(match.Groups[1].Value.ToString());
Run Code Online (Sandbox Code Playgroud)

错误是输入字符串不是正确的格式.它没有内部异常.

我试过它转换为toString()

   decimal rate = Convert.ToDecimal(match.Groups[1].Value.ToString());
Run Code Online (Sandbox Code Playgroud)

此外,我试图在字符串变量中取match的值,然后尝试在它上面做一个SubString逻辑.但它不工作

string test = match.ToString();
test=test.substring(0,test.Indexof("""));
Run Code Online (Sandbox Code Playgroud)

有一个引号("),所以我试图取字符串的值,直到".建议我如何解决这个问题.或者我还能在正确的方向上尝试什么.

Imr*_*zvi 0

尝试这个来获取网址。

    Uri uri = new Uri(string.Format("http://www.google.com/ig/calculator?hl=en&q={2}{0}%3D%3F{1}", CurrenctCurr.ToUpper(), DestinationCurr.ToUpper(), TotCurrentPay));
    string url = uri.AbsoluteUri + uri.Fragment;
    string response = web.DownloadString(url);
Run Code Online (Sandbox Code Playgroud)