C# 4.0 从字符串中删除字符而不知道其位置

C# 4.0 从字符串中删除字符而不知道其位置,c#-4.0,C# 4.0,我想在不知道其位置的情况下从字符串中删除字符('.')。 比如说 string test = "4.000"; 但是“.”永远都会改变 谢谢 如果您只想删除该字符的第一个匹配项: string newString = test.Remove(test.IndexOf(".", 1)); string newString = test.Replace(".", ""); 如果要删除该字符的所有出现次数,请执行以下操作: string newString = test.Remove(test.

我想在不知道其位置的情况下从字符串中删除字符('.')。 比如说

string test = "4.000";
但是“.”永远都会改变


谢谢

如果您只想删除该字符的第一个匹配项:

string newString = test.Remove(test.IndexOf(".", 1));
string newString = test.Replace(".", "");
如果要删除该字符的所有出现次数,请执行以下操作:

string newString = test.Remove(test.IndexOf(".", 1));
string newString = test.Replace(".", "");

如果只想删除该字符的第一个匹配项:

string newString = test.Remove(test.IndexOf(".", 1));
string newString = test.Replace(".", "");
如果要删除该字符的所有出现次数,请执行以下操作:

string newString = test.Remove(test.IndexOf(".", 1));
string newString = test.Replace(".", "");
使用

使用


你当然可以。换掉它?是的,我可以,但是为了什么?如果使用替换,我需要在其位置放置一些东西,真的吗?我只想删除它。你可以用一个空字符串替换它,它将返回被截断的结果。你可以只替换它吗?是的,我可以,但是为了什么?如果使用替换,我需要在其位置放置一些东西,真的吗?我只想删除它。你可以替换为一个空字符串,它将返回截断的结果,我使用了它。非常感谢,伙计们!是的,我用过。非常感谢,伙计们!