C# program to remove characters starting at a particular index in StringBuilder


Set StringBuilder −

StringBuilder str = new StringBuilder("Airport");

Let’s say you need to remove characters. For that, use the Remove() method, which removes a bunch of characters beginning with a particular index −

str.Remove(3, 4);

The above removes four characters beginning from 3rd index (i.e. 4th position) −

Here is the complete code −

Example

 Live Demo

using System;
using System.Text;

public class Program {
   public static void Main() {
      StringBuilder str = new StringBuilder("Airport");
      Console.WriteLine("String: "+str);

      // removing four characters
      Console.Write("String after removing characters: ");
      str.Remove(3, 4);
      Console.WriteLine(str);
   }
}

Output

String: Airport
String after removing characters: Air

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

59 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements