C# program to remove a range of characters by index using StringBuilder

CsharpProgrammingServer Side Programming

Use the Remove() method to remove a range of characters by index.

Let’s say you need to remove the last 5 characters from the following string −

StringBuilder myStr = new StringBuilder("Framework");

For that, set the Remove() method as −

str.Remove(3, 4);

The following is the complete code −


 Live Demo

using System;
using System.Text;

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

      // removing four characters
      Console.Write("New string: ");
      myStr.Remove(5, 4);


Initial String: Framework
New string: Frame
Published on 04-Sep-2018 07:54:32