Mono Class Library: System.Text.StringBuilder Overview | Members

System.Text.StringBuilder.Remove Method

Removes a specified range of characters from the current instance.

public StringBuilder Remove (int startIndex, int length)

Parameters

startIndex
A int containing the index at which to begin removal.
length
A int containing the number of characters to be removed.

Returns

The current instance after removal has occurred.

Exceptions

TypeReason
ArgumentOutOfRangeException

startIndex or length is less than zero

-or-

The sum of startIndex and length is greater than the length of the current instance.

Remarks

This method removes the specified range of characters from the current instance. The characters at (startIndex + length) are moved to startIndex, and the string value of the current instance is shortened by length.

Note: The StringBuilder.Replace(string, string) method can be used to remove all instances of a string from a System.Text.StringBuilder.

Example

C# Example

using System;
using System.Text;

public class StringBuilderTest  {
   public static void Main()  {
   
      StringBuilder sb = new StringBuilder("0123456789");
      Console.WriteLine(sb);
      sb.Remove(3, 4);
      Console.WriteLine(sb);
   }
}
   

The output is

0123456789
012789

Requirements

Namespace: System.Text
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0