字符串中的双引号转义 [英] Escape double quotes in a string
本文介绍了字符串中的双引号转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
双引号可以这样转义:
string test = @"He said to me, ""Hello World"". How are you?";
但这涉及到将字符
添加到是否存在C#函数或其他方法来转义双引号,以便不需要更改字符串?
But this involves adding character "
to the string. Is there a C# function or other method to escape double quotes so that no changing in string is required?
推荐答案
否。
要么按原样使用逐字字符串文字,要么使用反斜杠转义
。
Either use verbatim string literals as you have, or escape the "
using backslash.
string test = "He said to me, \"Hello World\" . How are you?";
在任何一种情况下,字符串均未更改-有一个转义的 。这只是一种告诉C#字符是字符串的一部分而不是字符串终止符的方式。
The string has not changed in either case - there is a single escaped "
in it. This is just a way to tell C# that the character is part of the string and not a string terminator.
这篇关于字符串中的双引号转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文