StringBuilder.Remove(Int32, Int32) Méthode

Définition

Supprime de cette instance la plage de caractères spécifiée.

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

Paramètres

startIndex
Int32

Position de base zéro dans cette instance où commence la suppression.

length
Int32

Nombre de caractères à supprimer.

Retours

Référence à cette instance après l'opération de suppression.

Exceptions

Si startIndex ou length est inférieur à zéro, ou startIndex + length est supérieur à la longueur de cette instance.

Exemples

L’exemple suivant illustre la Remove méthode.

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.
'

Remarques

La méthode actuelle supprime la plage de caractères spécifiée de l’instance actuelle. Les caractères à (startIndex + length) sont déplacés vers startIndex, et la valeur de chaîne de l’instance actuelle est raccourcie par length. La capacité de l’instance actuelle n’est pas affectée.

Notes

La Remove méthode modifie la valeur de l’instance actuelle StringBuilder et retourne cette instance. Il ne crée pas et ne retourne pas d’objet StringBuilder .

S’applique à

Voir aussi