使用RegEx将dot(。)替换为逗号(,)? [英] Replace dot(.) with comma(,) using RegEx?

查看:88
本文介绍了使用RegEx将dot(。)替换为逗号(,)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发C#应用程序。我想使用正则表达式用逗号(,)更改数字十进制数字。

I am working on a C# application. I want to change number decimal figure with comma(,) where i have dot(.) using regular expression.

例如:

Price= 100,00.56

表示数字值的国际规则,但我在瑞典使用数字的不同方式,例如

As this international rule of representing numeric values but I Sweden they have different ways for numbers Like

Price= 100.00,56

所以我想使用以下方式将dot(。)更改为逗号(,)并将逗号(,)更改为dot(。)正则表达式。可以为我提供指导。

So i want to change dot(.) into comma(,) and comma(,) into dot(.) using RegEx. Could guide me about this.

推荐答案

在格式化数字时,应使用字符串格式重载,它需要 CultureInfo 对象。瑞典的文化名称为 sv-SE,如此处所示

When formatting numbers, you should use the string format overload that takes a CultureInfo object. The culture name for swedish is "sv-SE", as can be seen here.

decimal value = -16325.62m;
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("sv-SE")));

编辑

@OregonGhost指出-解析数字也应使用 CultureInfo

As @OregonGhost points out - parsing out numbers should also be done with CultureInfo.

这篇关于使用RegEx将dot(。)替换为逗号(,)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆