How can we replace symbols from string in C#?
Like this
Input : "�Click me."
Output: "Click me."
;
A simplistic solution would be to strip all non-ASCII characters from your string. There are a couple of ways to do this available on this question, the simplest of which would probably be:
string s = "�Click me.";
s = Regex.Replace(s, @"[^\u0000-\u007F]", "");
Although as mentioned, this may be an encoding/codepage issue -- using a regex here may not necessarily be the appropriate solution.
EDIT: Based on your comments, here are a couple other patterns you can try:
Remove all non-ASCII characters and ASCII control characters:
s = Regex.Replace(s, @"[^\u0020-\u007F]", "");
Remove everything except for alphanumeric ASCII characters:
s = Regex.Replace(s, @"[^A-Za-z0-9]", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With