How do I write escape characters verbatim (without escaping) in C# using StreamWriter?

Posted by Joel on Stack Overflow See other posts from Stack Overflow or by Joel
Published on 2010-04-26T19:29:18Z Indexed on 2010/04/26 19:33 UTC
Read the original article Hit count: 285

Filed under:
|
|
|

I'm writing a utility that takes in a .resx file and creates a javascript object containing properties for all the name/value pairs in the .resx file. This is all well and good, until one of the values in the .resx is

This dealer accepts electronic orders.

/r/nClick to order {0} from this dealer.

I'm adding the name/value pairs to the js object like this:

streamWriter.Write(string.Format("\n{0} : \"{1}\"", kvp.Key, kvp.Value));

When kvp.Value = "This dealer accepts electronic orders./r/nClick to order {0} from this dealer."

This causes StreamWriter.Write() to actually place a newline in between 'orders.' and 'Click', which naturally screws up my javascript output.

I've tried different things with @ and without using string.Format, but I've had no luck. Any suggestions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about strings