StringBuilder.Remove(Int32, Int32) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Remove o intervalo de caracteres especificado dessa instância.
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
Parâmetros
- startIndex
- Int32
A posição baseada em zero nesta instância em que a remoção começa.
- length
- Int32
O número de caracteres a serem removidos.
Retornos
Uma referência a essa instância após a conclusão da operação de excise.
Exceções
Se startIndex ou length for menor que zero ou startIndex + length for maior que o comprimento dessa instância.
Exemplos
O exemplo a seguir demonstra o Remove método.
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.
'
Comentários
O método atual remove o intervalo especificado de caracteres da instância atual. Os caracteres em (startIndex + length) são movidos para startIndex, e o valor da cadeia de caracteres da instância atual é reduzido por .length A capacidade da instância atual não é afetada.
Note
O Remove método modifica o valor da instância atual StringBuilder e retorna essa instância. Ele não cria e retorna um novo StringBuilder objeto.