C# StringBuilder Remove

Description

StringBuilder Remove Removes the specified range of characters from this instance.

Syntax

StringBuilder.Remove has the following syntax.


public StringBuilder Remove(
  int startIndex,
  int length
)

Parameters

StringBuilder.Remove has the following parameters.

  • startIndex - The zero-based position in this instance where removal begins.
  • length - The number of characters to remove.

Returns

StringBuilder.Remove method returns A reference to this instance after the excise operation has completed.

Example

The following example demonstrates the Remove method.


/*from   w w w.  ja va  2  s. c  om*/
using System;
using System.Text;

class Sample 
{
    public static void Main() 
    {
        string str =   "The quick brown fox jumps over the lazy dog.";
        StringBuilder sb = new StringBuilder(str);
    
        sb.Remove(10, 6); // Remove "brown "
    
        Console.WriteLine("{0}", sb.ToString());
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding