• Avoiding escape characters in C#

    WinMan Member

    I’ve just started learning c# in earnest and have developed a basic program to help things at work. What the program does is simply parse specific text snippets from an xml file and then pastes that snippet into a text box, in the program selected process.

    At the moment the biggest issue is that there are a lot of accented and other special characters that I have to escape in the xml in order for the program to run properly.

    My question would be, is there are way to bypass the whole escaping shenanigans? I’ve found that some of the text snippets in the xml have become quite unmanageable because of that, i.e. when I need to paste in html code etc.

    Like I said, I’ve just started out so please excuse me if I used the wrong terms and let me know if you need any clarification on any of this.

  • MarkGrillo Member

    If I understand you correctly, you’re asking if you can prevent this:


    The only way I know is to use CDATA tags:


    Hope this helps. It’s not exactly clean as a user can now pass anything via XML and you won’t be able to validate it with the XSD for the outer XML.

  • Abhey Member

    I’m really not sure what you’re looking for, but C# supports verbatim strings which eliminates the headache with escape sequences.

    Console.WriteLine(@"Hell 'o' World")

    will print Hell ‘o’ World (Note that ‘ ‘ doesn’t require any escape sequences)

Viewing 2 reply threads
  • You must be logged in to reply to this topic.