Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

String.Remove Method (Int32)

Deletes all the characters from this string beginning at a specified position and continuing through the last position.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public string Remove (
	int startIndex
)
public String Remove (
	int startIndex
)
public function Remove (
	startIndex : int
) : String
Not applicable.

Parameters

startIndex

The position to begin deleting characters.

Return Value

A new String object that is equivalent to this string less the removed characters.

Exception typeCondition

ArgumentOutOfRangeException

startIndex is less than zero.

-or-

startIndex specifies a position that is not within this string.

The following code example demonstrates the Remove method. The next-to-last case removes all text starting from the specified index through the end of the string. The last case removes three characters starting from the specified index.

// This example demonstrates the String.Remove() method.
using System;

class Sample 
{
    public static void Main() 
    {
    string s = "abc---def"; 
//
    Console.WriteLine("Index: 012345678");
    Console.WriteLine("1)     {0}", s);
    Console.WriteLine("2)     {0}", s.Remove(3)); 
    Console.WriteLine("3)     {0}", s.Remove(3, 3));
    }
}
/*
This example produces the following results:

Index: 012345678
1)     abc---def
2)     abc
3)     abcdef

*/

// This example demonstrates the String.Remove() method.
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        String s = "abc---def";
        //
        Console.WriteLine("Index: 012345678");
        Console.WriteLine("1)     {0}", s);
        Console.WriteLine("2)     {0}", s.Remove(3));
        Console.WriteLine("3)     {0}", s.Remove(3, 3));
    } //main
} //Sample
/*
This example produces the following results:

Index: 012345678
1)     abc---def
2)     abc
3)     abcdef

*/

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

Show:
© 2014 Microsoft