Removing char in string from specific index

前端 未结 5 911
情话喂你
情话喂你 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:43

    You can write your on extension for this using the Remove method:

    public static class MyStringExtensions
    {
         public static string RemoveAt(this string s, int index)
         {
             return s.Remove(index, 1);
         }
    }
    

    usage:

    string s = "This is string";
    s = s.RemoveAt(2);
    

提交回复
热议问题