Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.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
C# 给出异常输入字符串的输出编号的格式不正确_C# - Fatal编程技术网

C# 给出异常输入字符串的输出编号的格式不正确

C# 给出异常输入字符串的输出编号的格式不正确,c#,C#,我有一些正则表达式来转换字符串 RRP ?142 - Now ?113 to just 142 为此,我使用的代码是 private Regex _originalPriceRegex = new Regex(@"[+-]?\d+(?:\.\d*)?"); 当程序从下面的函数返回值时,我得到异常 private string LookForOrignalPrice(HtmlNode node) { string text = node.InnerText; Match pri

我有一些正则表达式来转换字符串

RRP ?142 - Now ?113 to just 142
为此,我使用的代码是

private Regex _originalPriceRegex = new Regex(@"[+-]?\d+(?:\.\d*)?");
当程序从下面的函数返回值时,我得到异常

private string LookForOrignalPrice(HtmlNode node)
{
    string text = node.InnerText;
    Match priceMatch = _originalPriceRegex.Match(text);

    if (priceMatch.Success)
    {
        Console.WriteLine("++++++price is " + priceMatch + "++++++++++++++++++++++++");
        return priceMatch.Groups[1].Value; //Issue arising here
    }
    return null;
}
调用函数的代码是

{ProductProperties.priceOriginal, new HtmlElementLocator("//td[@class='tdRow1Color']//td[@class='plaintext']//text()[starts-with(., 'RRP')] | descendant::td[@class='tdRow1Color']/descendant::td[contains(text(), '£')] | //span[@style='font-weight:bold;color:White;']",
                customValueHandler: new CustomValueHandler(LookForOrignalPrice))
当函数返回函数的值时,问题似乎就出现了,因为它只返回一个数字。是否有办法将函数中的字符串转换为十进制或int以绕过异常。
感谢您提供的任何建议

您确定这就是例外情况的来源吗?FormatException通常是我希望在int.Parse或double.Parse中看到的。请显示调用上述方法的代码好吗?在函数返回值时,在代码上运行断点,我没有在代码中使用int.Parse或double.Parse添加调用该方法的代码可以逐字粘贴堆栈跟踪吗?我同意马特的看法,这似乎不太可能出现这种例外。