How To Remove Any Given Character From A String

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.

Next Recommended Reading C# String vs string: The Difference