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.