StringBuilder::Remove Method (Int32, Int32)
Removes the specified range of characters from this instance.
Assembly: mscorlib (in mscorlib.dll)
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.
| 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 example demonstrates the Remove method.
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. */
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
