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 −
Example
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);
Console.WriteLine(myStr);
}
}Output
Initial String: Framework New string: Frame