Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
The zero-based position in this instance where removal begins.
The number of characters to remove.
A reference to this instance after the excise operation has completed.
If startIndex
or length
is less than zero, or startIndex
+ length
is greater than the length of this instance.
The following example demonstrates the Remove method.
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.
'
The current method removes the specified range of characters from the current instance. 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.
Note
The Remove method modifies the value of the current StringBuilder instance and returns that instance. It does not create and return a new StringBuilder object.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in