Export (0) Print
Expand All

String.Remove Method (Int32)

Note: This method is new in the .NET Framework version 2.0.

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

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft