Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to remove a range of characters by index using StringBuilder
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
Advertisements