C# 按位置替换字符串 [英] C# Replace string by position

查看:154
本文介绍了C# 按位置替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试替换字符串中的逗号.

I am trying to replace a comma in a string.

例如,数据是零件的货币价值.

For example, the data is the currency value of a part.

例如.453,27 这是我从 SAP 数据库中得到的值

Eg. 453,27 This is the value I get from an SAP database

我需要将逗号替换为句点以将值固定为正确的数量.现在有时,它会在数以千计.

I need to replace the comma to a period to fix the value to the correct amount. Now sometimes, it will be in the thousands.

例如.2,356,34 这个值必须是2,356.34

Eg. 2,356,34 This value needs to be 2,356.34

因此,我需要帮助操作字符串以替换距离末尾 2 个字符的逗号.

So, I need help manipulating the string to replace comma that is 2 characters from the end.

感谢您的帮助

推荐答案

string x = "2,356,34";
if (x[x.Length - 3] == ',')
{
    x = x.Remove(x.Length - 3, 1);
    x = x.Insert(x.Length - 2, ".");
}

这篇关于C# 按位置替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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