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

CsharpProgrammingServer Side Programming

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
raja
Published on 04-Sep-2018 07:49:34
Advertisements