Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 views
in Technique[技术] by (71.8m points)

c# - How do I replace a backslash-double quote with just a double quote?

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.

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(""", @"""");
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

enter image description here

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...