Aracılığıyla paylaş


StringBuilder.Remove(Int32, Int32) Yöntem

Tanım

Belirtilen karakter aralığını bu örnekten kaldırır.

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

Parametreler

startIndex
Int32

Bu örnekte kaldırmanın başladığı sıfır tabanlı konum.

length
Int32

Kaldırılacak karakter sayısı.

Döndürülenler

Excise işlemi tamamlandıktan sonra bu örneğe başvuru.

Özel durumlar

Veya length sıfırdan küçükse veya startIndexlength + bu örneğin uzunluğundan büyükse.startIndex

Örnekler

Aşağıdaki örnekte yöntemi gösterilmektedir Remove .

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.

*/
open System.Text

let rule1 = "0----+----1----+----2----+----3----+----4---"
let rule2 = "01234567890123456789012345678901234567890123"
let str = "The quick brown fox jumps over the lazy dog."
let sb = StringBuilder str

printfn "StringBuilder.Remove method\n"
printfn "Original value:"
printfn $"{rule1}"
printfn $"{rule2}"
printfn $"{sb}\n"

sb.Remove(10, 6) |> ignore // Remove "brown "

printfn "New value:"
printfn $"{rule1}"
printfn $"{rule2}"
printfn $"{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.
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.
'

Açıklamalar

Geçerli yöntem, geçerli örnekten belirtilen karakter aralığını kaldırır. (startIndex + length) konumundaki karakterler öğesine startIndextaşınır ve geçerli örneğin dize değeri ile lengthkısaltılır. Geçerli örneğin kapasitesi etkilenmez.

Not

Remove yöntemi geçerli StringBuilder örneğin değerini değiştirir ve bu örneği döndürür. Yeni StringBuilder bir nesne oluşturmaz ve döndürmez.

Şunlara uygulanır

Ayrıca bkz.