Replace Double Quote with Empty String C#
I have a string that look like codes=”A,B,C”
, which I am getting after pa开发者_如何转开发rsing from a word document.
At the run time I just want to replace these double quotes with empty string.
I tried doing something like str.Replace("\"", "")
.
But above double quotes are not getting replaced :(
As codes=”A,B,C”
seems to have some different looking double quotes, not sure if that's causing the problem.
Please guide how can I replace these double quotes from above string.
Thank you!
The “
and ”
characters aren't the same as the "
character. How about this instead?
string clean = dirty.Replace("“", "").Replace("”", "");
The double quote character you have tried to replace is ASCII code 34. Word has used "smart quotes", which you should be able to insert in your code by holding down Alt and typing 0147 on the number keypad (the number key row won't work) and 0148.
These are the codes for those characters in the default ANSI code page for Windows I believe.
” look to me like one half of the smart quotes stuff a different thing to standard quotes. You will need to include them in your replacement code. Looking a character map they are U+201C and U+201D. Assuming the source is Unicode.
str.Replace("\"", string.Empty);
精彩评论