Skip to main content

Remove Special Characters from String using C#

Today, We want to share with you Remove Special Characters from String using C#.
In this post we will show you replace special characters in c#, hear for Trimming and Removing Characters from Strings in C# .NET we will give you demo and example for implement.
In this post, we will learn about C# – Best way to remove special All characters from a string with an example.

Remove Special Characters from String using C#

There are the Following The simple About Remove Special Characters from String using C# Full Information With Example and source code.

As I will cover this Post with live Working example to develop C# Program to remove special characters from a String , so the some major files and Directory structures for this example is following below.

  • Default.aspx.cs
Also Read :  How to Open URL in New Tab using CodeIgniter

Remove Special Characters from the Given String using C#

Default.aspx.cs

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as Default.aspx.cs.





    <title>Remove Special All Characters from the Given String using C#</title>


    <form id="form1">
        <div>
            <h2>How to remove All special characters from a string in asp.net c#</h2>
            <table style="width: 80%">
                <tr>
                    <td><b>C# Remove Special Characters from the Given String using regex:</b>
                        <br />
                        
                    </td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <br />
                        <b>C# Remove Special Characters from the Given String using Replace():</b>
                        <br />
                        
                    </td>
                    <td></td>
                </tr>
            </table>
        </div>
    </form>


using System;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // remove specific characters from String using C#
        FirstLblDisplay.Text = SpecialCharRemove("[email protected]#string.com");
        secondLblDisplay.Text = SpecialChaRegexrRemove("[email protected]#string.com");

    }

    protected string SpecialChaRegexrRemove(string param)
    {
        return param = System.Text.RegularExpressions.Regex.Replace(param, "[^a-zA-Z0-9_]+", " ");
    }

    protected string SpecialCharRemove(string myInp)
    {
        return myInp.Replace("#", "")
            .Replace("", "")
            .Replace("'", "").Replace("\", "");
    }
}

Angular 6 CRUD Operations Application Tutorials

Read :

Also Read :  PHP Laravel 5.6 Delete Multiple Rows using Checkbox

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Remove Special Characters from String using C#.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Web Developer

Hi, I’m Web developer, PHP developer.Pakainfo.com is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development.Any visitors of this site are free to browse our tutorials, live demos, Examples and download scripts.If you have a project that you want to get started, launch quickly, contact me. Email : [email protected]