Our end users still copy and paste things from Word and Excel into form fields and we end up with a lot of unwanted characters in our database tables. I've tried a bunch of things to remove unwanted characters from strings. The latest is a character like the following
I have tried the following to no avail:
summary = Regex.Replace(summary, @"[^\u0000-\u007F]+", string.Empty);
summary = Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(summary));
Does saving it to the database somehow change it's value?!?!
This does find the offending string in the DB
select *
from Project
where CharIndex(CHAR(2), summary) > 0
The server error that gets thrown is this:
System.ArgumentException: '', hexadecimal value 0x02, is an invalid character
which is why I tried the Regex solution first (\u0002 seems to be the offending character as far as C# is concerned)