Search code examples
c#escaping

How to prevent C# from escaping my string?


I have Windows Forms UI, that allows me to enter format for string formatting in TextBox, like:

Enter result format: {sku}:{value} \n

Problem is, that \n is getting escaped, so result format string in debug view looks like:

{sku}:{value} \\n

And that produces \n instead of line break in result.

So question is, how to prevent this, or how to remove escaping before using in StringBuilder.AppendFormat()

Update: I've decided to add image from notepad++ window, may be that will help understand what I need and why (although my use case is a bit different, I think idea is the same): enter image description here


Solution

  • Probably, what you want to do is to use the string.Replace(@"\n", "\n") method. View more at http://msdn.microsoft.com/en-us/library/system.string.replace.aspx