StringBuilder.Remove(Int32, Int32) StringBuilder.Remove(Int32, Int32) StringBuilder.Remove(Int32, Int32) StringBuilder.Remove(Int32, Int32) Method

Definition

Entfernt den angegebenen Bereich von Zeichen aus dieser Instanz.Removes the specified range of characters from this instance.

public:
 System::Text::StringBuilder ^ Remove(int startIndex, int length);
public System.Text.StringBuilder Remove (int startIndex, int length);
member this.Remove : int * int -> System.Text.StringBuilder
Public Function Remove (startIndex As Integer, length As Integer) As StringBuilder

Parameter

startIndex
Int32 Int32 Int32 Int32

Die nullbasierte Position in dieser Instanz, an der das Entfernen beginnt.The zero-based position in this instance where removal begins.

length
Int32 Int32 Int32 Int32

Die Anzahl der zu entfernenden Zeichen.The number of characters to remove.

Gibt zurück

Ein Verweis auf diese Instanz, nachdem der Ausschneidevorgang abgeschlossen wurde.A reference to this instance after the excise operation has completed.

Ausnahmen

Wenn startIndex oder length kleiner als 0 (null) ist oder startIndex + length größer als die Länge dieser Instanz sind.If startIndex or length is less than zero, or startIndex + length is greater than the length of this instance.

Beispiele

Das folgende Beispiel veranschaulicht die Remove Methode.The following example demonstrates the Remove method.

using namespace System;
using namespace System::Text;
int main()
{
   String^ rule1 = "0----+----1----+----2----+----3----+----4---";
   String^ rule2 = "01234567890123456789012345678901234567890123";
   String^ str = "The quick brown fox jumps over the lazy dog.";
   StringBuilder^ sb = gcnew StringBuilder( str );
   Console::WriteLine();
   Console::WriteLine( "StringBuilder.Remove method" );
   Console::WriteLine();
   Console::WriteLine( "Original value:" );
   Console::WriteLine( rule1 );
   Console::WriteLine( rule2 );
   Console::WriteLine( "{0}", sb );
   Console::WriteLine();
   sb->Remove( 10, 6 ); // Remove "brown "
   Console::WriteLine( "New value:" );
   Console::WriteLine( rule1 );
   Console::WriteLine( rule2 );
   Console::WriteLine( "{0}", sb );
}

/*
This example produces the following results:

StringBuilder.Remove method

Original value:
0----+----1----+----2----+----3----+----4---
01234567890123456789012345678901234567890123
The quick brown fox jumps over the lazy dog.

New value:
0----+----1----+----2----+----3----+----4---
01234567890123456789012345678901234567890123
The quick fox jumps over the lazy dog.

*/
using System;
using System.Text;

class Sample 
{
    public static void Main() 
    {
    string rule1 = "0----+----1----+----2----+----3----+----4---";
    string rule2 = "01234567890123456789012345678901234567890123";
    string str =   "The quick brown fox jumps over the lazy dog.";
    StringBuilder sb = new StringBuilder(str);

    Console.WriteLine();
    Console.WriteLine("StringBuilder.Remove method");
    Console.WriteLine();
    Console.WriteLine("Original value:");
    Console.WriteLine(rule1);
    Console.WriteLine(rule2);
    Console.WriteLine("{0}", sb.ToString());
    Console.WriteLine();

    sb.Remove(10, 6); // Remove "brown "

    Console.WriteLine("New value:");
    Console.WriteLine(rule1);
    Console.WriteLine(rule2);
    Console.WriteLine("{0}", sb.ToString());
    }
}
/*
This example produces the following results:

StringBuilder.Remove method

Original value:
0----+----1----+----2----+----3----+----4---
01234567890123456789012345678901234567890123
The quick brown fox jumps over the lazy dog.

New value:
0----+----1----+----2----+----3----+----4---
01234567890123456789012345678901234567890123
The quick fox jumps over the lazy dog.

*/
Imports System.Text

Class Sample
   Public Shared Sub Main()
      Dim rule1 As String = "0----+----1----+----2----+----3----+----4---"
      Dim rule2 As String = "01234567890123456789012345678901234567890123"
      Dim str As String   = "The quick brown fox jumps over the lazy dog."
      Dim sb As New StringBuilder(str)
      
      Console.WriteLine()
      Console.WriteLine("StringBuilder.Remove method")
      Console.WriteLine()
      Console.WriteLine("Original value:")
      Console.WriteLine(rule1)
      Console.WriteLine(rule2)
      Console.WriteLine("{0}", sb.ToString())
      Console.WriteLine()
      
      sb.Remove(10, 6) ' Remove "brown "

      Console.WriteLine("New value:")
      Console.WriteLine(rule1)
      Console.WriteLine(rule2)
      Console.WriteLine("{0}", sb.ToString())
   End Sub
End Class
'
'This example produces the following results:
'
'StringBuilder.Remove method
'
'Original value:
'0----+----1----+----2----+----3----+----4---
'01234567890123456789012345678901234567890123
'The quick brown fox jumps over the lazy dog.
'
'New value:
'0----+----1----+----2----+----3----+----4---
'01234567890123456789012345678901234567890123
'The quick fox jumps over the lazy dog.
'

Hinweise

Die aktuelle Methode entfernt den angegebenen Zeichenbereich aus der aktuellen Instanz.The current method removes the specified range of characters from the current instance. Die Zeichen an (startIndex + startIndex) werden in verschoben, und der Zeichen folgen Wert der aktuellen Instanz wird um lengthverkürzt.lengthThe characters at (startIndex + length) are moved to startIndex, and the string value of the current instance is shortened by length. Die Kapazität der aktuellen Instanz ist nicht betroffen.The capacity of the current instance is unaffected.

Hinweis

Die Remove -Methode ändert den Wert der aktuellen StringBuilder Instanz und gibt diese Instanz zurück.The Remove method modifies the value of the current StringBuilder instance and returns that instance. Es wird kein neues StringBuilder -Objekt erstellt und zurückgegeben.It does not create and return a new StringBuilder object.

Gilt für:

Siehe auch