简体   繁体   English

用空字符串C#替换双引号

[英]Replace Double Quote with Empty String C#

I have a string that look like codes=”A,B,C” , which I am getting after parsing from a word document. 我有一个看起来像是codes=”A,B,C”的字符串,它是从Word文档中解析后得到的。

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 :( 我尝试做类似str.Replace("\\"", "")事情str.Replace("\\"", "")但是上面的双引号没有被替换:(

As codes=”A,B,C” seems to have some different looking double quotes, not sure if that's causing the problem. 由于codes=”A,B,C”似乎有一些不同的双引号,因此不确定是否是引起问题的原因。

Please guide how can I replace these double quotes from above string. 请指导如何替换上面字符串中的双引号。

Thank you! 谢谢!

字符与 "字符不同。如何处理呢?

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. 您尝试替换的双引号字符是ASCII代码34。Word使用了“智能引号”,您可以通过按住Alt并在数字小键盘上键入0147来插入代码中(数字键行不会t work)和0148。

These are the codes for those characters in the default ANSI code page for Windows I believe. 我相信这些是Windows的默认ANSI代码页中这些字符的代码。

” 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. 从字符映射表来看,它们是U + 201C和U + 201D。 Assuming the source is Unicode. 假设源是Unicode。

str.Replace("\"", string.Empty);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM