gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:35:07 26 4
gpt4 key购买 nike

我有这样的值(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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com