Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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# 为什么我的£;100000转换为100而不是100000,是否可能与正则表达式有关?_C#_Regex - Fatal编程技术网

C# 为什么我的£;100000转换为100而不是100000,是否可能与正则表达式有关?

C# 为什么我的£;100000转换为100而不是100000,是否可能与正则表达式有关?,c#,regex,C#,Regex,我有以下代码: var totalDecimalList = Regex.Split(total, @"[^0-9\.]+").Where(c => c != "." && c.Trim() != ""); decimal totalDecimal = decimal.Parse(totalDecimalList.First()); 通过我的调试会话 totalDecimal = 100 and not 100000 所以“,”显然是问题的原因,第一行ie中的正则表达式

我有以下代码:

var totalDecimalList = Regex.Split(total, @"[^0-9\.]+").Where(c => c != "." && c.Trim() != "");
decimal totalDecimal = decimal.Parse(totalDecimalList.First());
通过我的调试会话

totalDecimal = 100 and not 100000
所以“,”显然是问题的原因,第一行ie中的正则表达式不正确

@"[^0-9\.]+")
如何更正此正则表达式以解释逗号


谢谢。

在要匹配的字符的括号表达式中添加逗号 e、 g


更好的是,让内置解析函数为您完成以下工作:

using System;
using System.Globalization;

namespace StackOverflow_CurrencyParsing
{
    class Program
    {
        static void Main(string[] args)
        {
            string total = "£100,000.00";

            decimal totalDecimal = decimal.Parse(total, NumberStyles.Currency, CultureInfo.GetCultureInfo("en-gb"));

            Console.WriteLine($"Total: {totalDecimal}");
            Console.ReadKey();
        }
    }
}

您是否尝试将逗号添加到[^0-9\.]中?e、 g[^0-9,\.]谢谢,已经排序好了。很简单:)请把答案写下来,我会记下来的。谢谢
using System;
using System.Globalization;

namespace StackOverflow_CurrencyParsing
{
    class Program
    {
        static void Main(string[] args)
        {
            string total = "£100,000.00";

            decimal totalDecimal = decimal.Parse(total, NumberStyles.Currency, CultureInfo.GetCultureInfo("en-gb"));

            Console.WriteLine($"Total: {totalDecimal}");
            Console.ReadKey();
        }
    }
}