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 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 = "";
  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! :)

No comments:

All Rights Reserved by Etechpulse © 2015 - 2016
Powered By Blogger

Contact Form


Email *

Message *

Powered by Blogger.