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