-5

I'm having a bit of trouble trying to write a single " to a file in C# as I can't seem to get the escape sequence to work. The idea being I want to write the line survey id="6737AF7F-F422-4995-B781-B3DE315DFE6D" to a file where the GUID itself is user input.

my current code for this is

XML.Add("<survey id=" + "\"\"" + surveyGUID.Text + "\"\"" + ">");

which writes survey id=""6737AF7F-F422-4995-B781-B3DE315DFE6D"".

Every variation I've tried either won't build, comes out the same way or writes survey id=\"6737AF7F-F422-4995-B781-B3DE315DFE6D\". Can this be done? Is there another escape sequence I don't know about?

Any help would be greatly appreciated.

James Morrison
  • 1,954
  • 2
  • 21
  • 48
  • 1
    Why are you manually writing out your XML? There are plenty of classes for that. Check out [this question](http://stackoverflow.com/questions/284324/how-can-i-build-xml-in-c) to make your life easier. – krillgar Sep 27 '16 at 18:32
  • it was not showing it.. it is now.. – MethodMan Sep 27 '16 at 18:33

2 Answers2

4

Here's what you want:

XML.Add("<survey id=" + "\"" + surveyGUID.Text + "\"" + ">");
rory.ap
  • 34,009
  • 10
  • 83
  • 174
1

just remove one of your escaped quotes on each side.

XML.Add("<survey id=" + "\"" + surveyGUID.Text + "\"" + ">");
Neil Locketz
  • 4,228
  • 1
  • 23
  • 34