StringBuilder.Remove Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Removes the specified range of characters from this instance.
Assembly: mscorlib (in mscorlib.dll)
'Declaration Public Function Remove ( _ startIndex As Integer, _ length As Integer _ ) As StringBuilder
Parameters
- startIndex
- Type: System.Int32
The zero-based position in this instance where removal begins.
- length
- Type: System.Int32
The number of characters to remove.
Return Value
Type: System.Text.StringBuilderA reference to this instance after the excise operation has completed.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | If startIndex or length is less than zero, or startIndex + length is greater than the length of this instance. |
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. |
The following code example demonstrates the Remove method.
Imports System.Text Class Example Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) 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) outputBlock.Text &= vbCrLf outputBlock.Text &= "StringBuilder.Remove method" & vbCrLf outputBlock.Text &= vbCrLf outputBlock.Text &= "Original value:" & vbCrLf outputBlock.Text &= rule1 & vbCrLf outputBlock.Text &= rule2 & vbCrLf outputBlock.Text += String.Format("{0}", sb.ToString()) & vbCrLf outputBlock.Text &= vbCrLf sb.Remove(10, 6) ' Remove "brown " outputBlock.Text &= "New value:" & vbCrLf outputBlock.Text &= rule1 & vbCrLf outputBlock.Text &= rule2 & vbCrLf outputBlock.Text += String.Format("{0}", sb.ToString()) & vbCrLf 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. '
Note: