tags:

views:

88

answers:

1

Is there a built method in .Net for C-style escaping of strings?

For example, I have to convert a string which contains quotes like "hello", and write it as an escaped string \"hello\".

Actually, to be more precise:

string original = "\"hello\"";

should be converted to

string what_i_need = "\\\"hello\\\"";

I could have probably done it myself while writing this question, but I don't want to reinvent hot water.

[Edit] According to the provided answer, this is actually a duplicate of: Can I convert a C# string value to a string literal. It didn't pop out since there were no tags and keywords I was looking for.

+1  A: 

I dont think there is any built in methods. But if you have to write your own, Can I convert a C# string value to a string literal post maybe helpful

cornerback84
+1, thanks, I will check the code provided by Cristi Diaconescu: http://stackoverflow.com/questions/323640/can-i-convert-a-c-string-value-to-a-string-literal/323670#323670.
Groo