如何将反斜杠双引号替换为仅双引号? [英] How do I replace a backslash-double quote with just a double quote?
问题描述
我一直在努力进行简单的替换.并需要一个好的解决方案.背景:这是一个用\编码的xml字符串,并且必须为"才能使用serializer.Deserialize对它进行反序列化.
I have struggled with a simple replace. And need a good solution. Background: It is a xml string encoded with \" and these need to be " to be able to deserialize it with serializer.Deserialize.
我想将反斜杠doublequot替换为一个双引号,例如"\" hello \"这样的字符串,因此字符串为" hello".文本很长,因此无法删除反斜杠.感谢您的指教.我认为应该是
I want to replace backslash doublequot with one double quot a string like " \"hello\" " so the string are " "hello" ". The text is long so it is not possible to remove backslash. Thanks for advise. I think it should have been
string s= "\" teetete \"";
string t;
t = s.Replace("\"", @"""");
推荐答案
您的示例字符串不包含任何反斜杠,您只是使用它来屏蔽双引号.这在开头包含一个反斜杠,在结尾包含一个反斜杠:
Your sample string doesn't contain any backslashes, you are just using it to mask the double quotes. This contains one backslash at the beginning and one at the end:
string s = "\\\" teetete \\\"";
如果要用单引号将其替换:
If you want to replace it with a single double quote:
string t = s.Replace("\\\"", "\"");
您必须查看调试器中的放大镜以查看字符串的真实值:
You have to look click at the loupe in the debugger to see the real value of a string:
这篇关于如何将反斜杠双引号替换为仅双引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!