Replace All Special Characters with Underscore Or Space in asp.net c#

Simple method to replace all the special characters with underscore or space.

Here is the code, while inserting data you can replace characters with this code step.

cmd.Parameters.AddWithValue("@column_name", Regex.Replace(txt_hedng.Text, "[^a-zA-Z0-9]+", "_"));

Another Example

 string quote = "being #cool is so difficult !!";

string replace = Regex.Replace(quote"[^a-zA-Z0-9_]+"" ");


Output

being cool is so difficult


Comments

Popular posts from this blog

Disable right click, Inspect Element and page source using JavaScript in Html and asp.net

Like Operator In Sql Server