How to remove special characters from an string - C#

random

How to remove special characters from an string - C#


Replace Special Characters in C#


In previous articles I explained about .Net Framework - An Introduction, Datetime to String format - C#, Convert Datatable to JSON in ASP.net using C#

In this article I will explain about an efficient way to remove special characters from string in c#. We have many ways to remove special characters from string value:-

Method 1
protected void RemoveSpecialChar(string str)
{
  str = "etechpulse@rk-aspdotnet#string.com";
  string result = System.Text.RegularExpressions.Regex.Replace(str, "[^a-zA-Z0-9_]+", " ");

}

c#,how to remove,special character list, special character a, string, string array

Method 2
protected string RemoveSpecialChar(string vInput)
    {
        return vInput.Replace("#", "")
            .Replace("<", "")
            .Replace(">", "")
            .Replace("'", "").Replace("\\", "");

    }
Please leave your comments, suggestions and queries about this post in the comment sections in order for me to improve my writing skills and to showcase more useful posts. Thanks for reading! :)
How to remove special characters from an string - C# Reviewed by Ravi Kumar on 12:25 PM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form

Name

Email *

Message *

Powered by Blogger.