加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 使用Google货币转换API时,输入字符串不是正确的格式

发布时间:2020-12-16 07:39:48 所属栏目:asp.Net 来源:网络整理
导读:我的应用程序是在C#.Net编码的Asp.Net MVC3中. 我使用谷歌货币转换API来获得转换. Google Currency Conversion API 我将From Currency和To Currency值和金额传递给我的Controller. 下面是我的C#代码. WebClient web = new WebClient(); string url = string.
我的应用程序是在C#.Net编码的Asp.Net MVC3中.
我使用谷歌货币转换API来获得转换.

Google Currency Conversion API
我将From Currency和To 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);

我在网上收到错误

decimal rate = Convert.ToDecimal(match.Groups[1].Value.ToString());

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

我试过它转换为toString()

decimal rate = Convert.ToDecimal(match.Groups[1].Value.ToString());

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

string test = match.ToString();
test=test.substring(0,test.Indexof("""));

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

解决方法

试试这个以获取网址.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读