Removing char in string from specific index

前端 未结 5 910
情话喂你
情话喂你 2021-02-18 14:25

Is there any function in C# that remove from string on specific index, for example

string s = \"This is string\";

s.RemoveAt(2);

s is now \"Th

5条回答
  •  不知归路
    2021-02-18 14:47

    As many others have said, there's a Remove method. What the other posts haven't explained is that strings in C# are immutable -- you cannot change them.

    When you call Remove, it actually returns a new string; it does not modify the existing string. You'll need to make sure to grab the output of Remove and assign it to a variable or return it... just calling Remove on its own does not change the string.

提交回复
热议问题