Export (0) Print
Expand All

StringBuilder.Remove Method

Removes the specified range of characters from this instance.

Namespace:  System.Text
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.StringBuilder
A reference to this instance after the excise operation has completed.

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

NoteNote:

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


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft