Open In App

C# | Remove() Method

In C#, Remove() method is a String Method. It is used for removing all the characters from the specified position of a string. If the length is not specified, then it will remove all the characters after specified position. This method can be overloaded by changing the number of arguments passed to it.

Syntax:



public string Remove(int StartIndex)  
or
public string Remove(int StartIndex, int count)  

Explanation:
public string Remove(int StartIndex) method will take a single parameter which is the starting index or we can say the specified position from where it will start to remove characters from the current String object. And this method will continue to remove the characters till the end of the current string object.

public string Remove(int StartIndex, int count) method will take two arguments i.e first is start position of specified string and the second one is the number of characters to be removed. The return type value of both the methods is System.String.



Exceptions: There can be two cases where exception ArgumentOutOfRangeException may occur are as follows:

Below are the programs to demonstrate the above Methods :

Important Point to Remember:

References:
https://msdn.microsoft.com/en-us/library/system.string.remove1

https://msdn.microsoft.com/en-us/library/system.string.remove2


Article Tags :
C#