C# String Remove(Int32)

Description

String Remove(Int32) returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted.

Syntax

String.Remove(Int32) has the following syntax.


public string Remove(
  int startIndex
)

Parameters

String.Remove(Int32) has the following parameters.

  • startIndex - The zero-based position to begin deleting characters.

Returns

String.Remove(Int32) method returns A new string that is equivalent to this string except for the removed characters.

Example

This example demonstrates the String.Remove() method.


//from   w ww. j a  v a 2 s.co m
using System;

class Sample 
{
    public static void Main() 
    {
        string s = "abc---def"; 
        
        Console.WriteLine(s);
        Console.WriteLine(s.Remove(3)); 
        Console.WriteLine(s.Remove(3, 3));
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version