删除c#中的转义序列
我想将字符串 test= "\"hi hello\" "
中的转义序列替换为字符串 test=" "hi hello" "
。基本上我想将 \"
替换为 "
。有什么建议吗?
I would like to replace the escape sequence from string test= "\"hi hello\" "
to string test=" "hi hello" "
. Basically I want to replace \"
to "
. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是不可能的,因为如果删除转义序列,您将得到一个无效的字符串。
您可以使用逐字字符串文字,但这些也需要转义双引号。
您能解释一下为什么要删除转义序列吗?当您输出字符串时它们将不可见。
调试器将显示转义序列作为辅助,但如果输出字符串,您将看不到它们。
This is not possible, as if you remove the escape sequences, you will have an invalid string.
You can use verbatim string literals, but these also require escaping of double quotes.
Can you please explain why you want to remove the escape sequences? They will not be visible when you output a string.
The debugger will display the escape sequences as an aid, but if you output the string, you will not see them.
这会
产生hi hello 。
在控制台上
This produces
hi hello
on the Console.
如果您不想替换字符串中的
\
,则您的选项仅限于逐字字符串:请注意,
\"
已替换为""
If you're not looking for replacing
\
in a string, your options are limited to a verbatim string:Note the
\"
was replaced with""