Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace all special character into a string using C# [closed]

Tags:

c#

regex

I would like to replace all special characters in a string with a comma (,).

For Example:

Hello@Hello&Hello(Hello) 

the output -

Hello,Hello,Hello,Hello, 

(I don't known how to use regexp in C#)

Can i do this work using regexp in C#?

like image 211
user3233403 Avatar asked Jan 27 '14 17:01

user3233403


People also ask

How do you handle special characters in C#?

C# includes escaping character \ (backslash) before these special characters to include in a string. Use backslash \ before double quotes and some special characters such as \,\n,\r,\t, etc. to include it in a string.


1 Answers

Yes, you can use regular expressions in C#.

Using regular expressions with C#:

using System.Text.RegularExpressions;  string your_String = "Hello@Hello&Hello(Hello)"; string my_String =  Regex.Replace(your_String, @"[^0-9a-zA-Z]+", ","); 
like image 121
Ishan Jain Avatar answered Sep 16 '22 15:09

Ishan Jain