I have a text file which I attached in this post.I read this file using StreamReader in c# and insert into SQL. When I try to insert the data,I get error.I was trying to find the problem for that i tried removing the text word by word from the text file and trying the code again.Finally I found the problematic part , removed it and successfully inserted into SQL . When I copy the text and paste into notepad ,there is nothing I could observe. . After spending some time I decided putting into word. I copied the text and paste into word 2007 and found the problem.The problematic text has hidden characters in it. The character is "--" . Two hyphens or dashes. According to my research , SQL database does not accept this Character sequence against SQL injection .After finding the issue, I tried to fix it. What I tried is , read the text file and if i see that sequence replace with new characters . I tried stream reader to read the text file but i can not find the hidden characters with stream reader . what is the best way to read hidden characters with c# .
I attached the file if you open in word you see the characters also in notepad++ . But not in notepad
Loading
Sam HobbsPosted Nov 13, 2010, 10:06 PM
theLizardPosted Nov 13, 2010, 7:48 PM
Note, "--" by the looks is a double Soft Hyphen what you should be looking for is a single "-" but it may also depend on the language of the region the email came from.
muharrem akerPosted Nov 13, 2010, 7:31 PM
thanks again
theLizardPosted Nov 12, 2010, 8:12 PM
Looking at the character map, what you describe are most likely Soft Hyphens U+00AD but can also be Macrons or Hebrew Point Patah U+05B7 or any number of other similar characters so depending on the region you are in and the language of the region.
Once you know exactly what they are you can filter these out by looking for the control character code in your C# code.