C# - String.Remove() Method with Example

Learn, how to check given a string and we have to remove specific substring in C#?
[Last updated : March 20, 2023]

String.Remove() Method

The String.Remove() method removes given number of characters from a string.

Syntax

String String.Remove(int startIndex, int count);

Parameter(s)

  • startIndex : is the index from where we have to remove the characters (string).
  • count : is the total number of characters to be removed.

C# program to check given a string and we have to remove specific substring

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1 {
  class Program {
    static void Main() {
      String str1;
      String str2;

      Console.Write("Enter String : ");
      str1 = Console.ReadLine();

      str2 = str1.Remove(0, 5);

      Console.WriteLine("String after remove method : " + str2);
    }
  }
}

Output

Enter String : This is India
String after remove method : is India

C# Basic Programs »


ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.