将String转换为Double C时出现异常#

时间:2014-09-05 13:07:10

标签: c# parsing double

我从四个不同的页面和不同的域中获取数据。

1- .com

2- .co.uk

3- .ca

4- .co.jp

对于以上所有内容,我从Html中获取数字并使用line将其转换为Double:

string  lowestSellerPrice = (Convert.ToDouble(fbalPrice) + 
                             Convert.ToDouble(fbalsPrice)).ToString();

这适用于前3个域,但对于.co.jp,即使fbalPricefbalsPrice中始终有一个数字,它总是给出异常:

Input string was not in a correct format

任何建议,因为我一直在努力解决这个问题太长时间没有结果我也尝试了try parse解决方案,但没有运气。

更新

见:

enter image description here

1 个答案:

答案 0 :(得分:0)

我解决了这个问题:

字符串就像" 1234"和" 111"然后我做了替换("",""); 。只有数字解除这个但是没有用,所以我做了这个:

 if (fbalPrice.Contains(" "))
     {
     fbalPrice = fbalPrice.Remove(0, fbalPrice.IndexOf(" ") + 1).Replace(",","").Trim();
     }
 if(fbalsPrice.Contains(" "))
     {
     fbalsPrice = fbalsPrice.Remove(0, fbalsPrice.IndexOf(" ") + 1).Replace(",", "").Trim();
     }

然后添加它们并且它有效。