The Remove method in C# is employed to obtain a fresh string by eliminating all characters starting from a specified beginIndex up to a given length. In cases where the length parameter is not provided, it deletes all characters following the beginIndex.
Signature
Example
public string Remove(Int32 beginIndex)
public string Remove(Int32 beginIndex, Int32 length)
Parameter
index: it is an integer type parameter.
Return
It returns a string.
C# String Remove Method Example
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "Hello C#";
string s2 = s1.Remove(2);
Console.WriteLine(s2);
}
}
Output:
C# String Remove Method Example 2
Example
using System;
public class StringExample
{
public static void Main(string[] args)
{
string s1 = "abcdefghijk";
string s2 = s1.Remove(4, 5);
Console.WriteLine(s2);
}
}
Output:
Output
abcdjk