find and solve || findandsolve.com
Please wait.....

C# String Remove Method

String.Remove() method is removing a given number of all characters from a string at a specified position. Simple it is use erase or delete from a string at a specified positionin a string, or erase the first character. Remove() acts on strings.

If you want to delete or erases a specifield  position of length, then you need to specify the starting position and length of characters to delete from the given string.


C# String Remove Method Syntax

public string Remove(Int32 beginIndex)  

public string Remove(Int32 beginIndex, Int32 length)  
Parameter

beginIndex: it is an integer type parameter.

Return

It returns a string.


C# String Remove() Method 

Example
    using System;
    public class StringContainsExample     {
        public static void Main(string[] args)
        {
          string str = "Hello Find And Solve";
          Console.WriteLine("Remove Result: {0}", str.Remove(4));
          Console.WriteLine("Remove with Length: {0}", str.Remove(2, 5));
          Console.ReadLine();
        }
    }    

output

Remove Result: Hell
Remove with Length: Heind And Solve

In the given above example, you used a string Remove() method to remove characters starting from position 4 till the end of the defined string and another Remove() method to delete 5 characters starting from position 2.


Other Example

    using System;
    public class StringContainsExample
    {
        public static void Main(string[] args)
        {
             string str = "Hello C#";
            string str1 = str.Remove(4);
            Console.WriteLine(str1);
        }
    }