我想逃离 \
和 "
在我的字符串中是这样的:
text.Replace("\\", "\\\\").Replace("\"", "\\\"");
但是 text
的结果,arash "moeen"
结果是arash \\\"moeen\\\"
我怎样才能解决这个问题?
最佳答案
只需使用 @
对于逐字文字字符串。
text.Replace(@"this", @"that");
例子:
text.Replace(@"\", @"\\").Replace(@"""", @"\""");
关于c# - 转义 C# 字符串中的双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26115253/