- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 n-th character from a string
To remove a character, use the remove() method and set the index from where you want to delete the character.
Firstly, set the string.
string str1 = "Amit"; Console.WriteLine("Original String: "+str1);
To delete a character at position 4.
StringBuilder strBuilder = new StringBuilder(str1); strBuilder.Remove(3, 1);
You can try to run the following code to remove nth character from a string.
Example
using System; using System.Text; public class Demo { public static void Main(string[] args) { string str1 = "Amit"; Console.WriteLine("Original String: "+str1); StringBuilder strBuilder = new StringBuilder(str1); strBuilder.Remove(3, 1); str1 = strBuilder.ToString(); Console.WriteLine("String after removing a character: "+str1); } }
Output
Original String: Amit String after removing a character: Ami
Advertisements