在 C# 字符串中转义双引号

ara*_*een 5 c# string escaping double-quotes

我试图逃脱\"在我的字符串中像这样:

text.Replace("\\", "\\\\").Replace("\"", "\\\"");
Run Code Online (Sandbox Code Playgroud)

但结果为text

arash "moeen"
Run Code Online (Sandbox Code Playgroud)

结果是

text.Replace("\\", "\\\\").Replace("\"", "\\\"");
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

B.K*_*.K. 6

仅用于@逐字字符串。

text.Replace(@"this", @"that");
Run Code Online (Sandbox Code Playgroud)

例子:

text.Replace(@"\", @"\\").Replace(@"""", @"\""");
Run Code Online (Sandbox Code Playgroud)