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

System.Text.StringBuilder.Remove Method

Removes a specified range of characters from the current instance. [Edit]

public StringBuilder Remove (int startIndex, int length)

Parameters

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

Returns

The current instance after removal has occurred. [Edit]

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.

[Edit]

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.

[Edit]

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