Hello, Friend I hope you doing good.
If you are searching for how to remove a given character from a string then don't go anywhere you are in the right place, read this blog and you definitely solve your problem.
So I understood what I'm going to do, First, take a string variable assign lines of code and then take a character variable and assign a value which character value do you want to remove then again I find out the char value in the string, and the using string method remove to remove from its current matched index.
Let us write code here,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeleteGivenCharacter {
class Program {
static void Main(string[] args) {
string str = "Hello every one";
char ch = 'e';
Console.WriteLine("Before removing character:- {0}\n", str);
for (int i = 0; i < str.Length - 1; i++) {
if (str[i] == ch) {
str = str.Remove(i, 1);
}
}
Console.WriteLine("After removing character '{0}' from string,\nfinal string is '{1}'", ch, str);
Console.ReadKey();
}
}
}
There is the output,

I hope you like this blog, if you have any doubt then ask me in the comment box.

Mukesh SagarPosted Dec 13, 2023, 7:17 AM
Here in the example while removing the character 'e' from string, the last character is left. To remove that also you need to replace the [for (int i = 0; i < str.Length - 1; i++) ] to [for (int i = 0; i < str.Length; i++) ]
Mukesh SagarPosted Sep 5, 2022, 4:52 AM
In order to replace all the specific characters, the code is to be modified as : for (int i = 0; i < str.Length; i++) { if (str[i] == ch) { str = str.Remove(i, 1); } }
Mukesh SagarPosted Sep 5, 2022, 4:50 AM
As per the current code, if we run it the output is :Before removing character:- Hello every oneAfter removing character 'e' from string, final string is 'Hllo vry one'
Mukesh SagarPosted Sep 1, 2022, 7:59 AM
It is not replacing the last character "e" in final output string. for (int i = 0; i < str.Length - 1; i++) { if (str[i] == ch) { str = str.Remove(i, 1); } }