c# - C# 中的字符串格式

标签 c# string.format

我有这样的值(value)观

1,000
25,000
500,000

需要将上面的值转换成下面这样不带逗号

1000
25000
500000

如何在 C# 中实现这一点?

如何得到这个的反向输出-

string.Format("{0:n}", 999999)

最佳答案

您可以像这样使用字符串类的Replace 函数:

string str = "25,000";
str = str.Replace(",", "");

编辑:

根据评论中的 Matthew Watson 建议

If the string is returned from string.Format("{0:n}", 999999) run on a machine in a locale that uses "." as the thousands separator, this will fail

更新的答案:

string num = "25,000";
NumberFormatInfo currentInfo = CultureInfo.CurrentCulture.NumberFormat;
num = num.Replace(currentInfo.NumberGroupSeparator, ""); 

关于c# - C# 中的字符串格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16601968/

相关文章:

java - 设置数组格式以将文本以表格格式附加到 TextField 中

java - 将对话消息/标题移至右侧

c# - 以CSV格式导出到EXCEL时用逗号(,)分隔字符串c#

c# - 硬删除 Salesforce 中的自定义字段

c# - 使用c#从mysql返回两个值

c# - 传输数据的 Symbol.WPAN.Bluetooth 示例

C# String.Format 可选参数

c# - Grpc.Core.Channel 和 Grpc.Net.Client.GrpcChannel 有什么区别?

c# - LINQ Guid toString()

c# - String.Format 和 StringBuilder 一样高效吗