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

Определение

Удаляет указанный диапазон символов из данного экземпляра.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

Параметры

startIndex
Int32 Int32 Int32 Int32

Отсчитываемая с нуля позиция в данном экземпляре, с которой начинается удаление.The zero-based position in this instance where removal begins.

length
Int32 Int32 Int32 Int32

Число знаков для удаления.The number of characters to remove.

Возвраты

Ссылка на этот экземпляр после завершения операции удаления.A reference to this instance after the excise operation has completed.

Исключения

Если startIndex или length меньше нуля или startIndex + length больше длины этого экземпляра.If startIndex or length is less than zero, or startIndex + length is greater than the length of this instance.

Примеры

В следующем примере демонстрируется Remove метод.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
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 'Main
End Class 'Sample
'
'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.
'

Комментарии

Текущий метод удаляет указанный диапазон символов из текущего экземпляра.The current method removes the specified range of characters from the current instance. СимволыstartIndexв (length startIndex) перемещаются в, а строковое значение текущего экземпляра сокращается lengthна. + The characters at (startIndex + length) are moved to startIndex, and the string value of the current instance is shortened by length. Емкость текущего экземпляра не затрагивается.The capacity of the current instance is unaffected.

Примечание

Метод изменяет значение текущего StringBuilder экземпляра и возвращает этот экземпляр. RemoveThe Remove method modifies the value of the current StringBuilder instance and returns that instance. Он не создает и не возвращает новый StringBuilder объект.It does not create and return a new StringBuilder object.

Применяется к

Дополнительно