以下是我的源数据。
string s = "text"some text in quotes next text.";
当我尝试分配时,它会抛出错误。
当我在“之前使用这个\
转义字符时,它工作正常。
string s = "text\"some text in quotes\" next text.";
但我的客户只会发送以下数据
text“引号中的一些文字下一篇文字。
如何将上述值分配给字符串?
我尝试使用如下所示,但抛出错误。
string a1 = @"text"some text in quotes next text.";
答案 0 :(得分:1)
逃避双引号:
string s = "text\"some text in quotes next text.";
替代:
string s = @"text""some text in quotes next text.";
因此,如果您收到字符串,或者从xml解析它,请在将其分配给字符串变量之前查找双引号并如上所述转义它们,例如:
string s = xmlValue.Replace('"', '\"');