c#双引号问题

本文关键字:问题 | 更新日期: 2023-09-27 18:11:22

以下是我的原始数据

string s = "text"some text in quotes next text.";

当我尝试赋值时,它抛出了一个错误。

当我在"之前使用这个'转义字符时,它工作正常。

string s = "text'"some text in quotes'" next text.";

但是我的客户端只会发送以下数据

text

如何将上述值赋给string?

我试过使用下面的方法,但是抛出错误。

string a1 = @"text"some text in quotes next text.";

c#双引号问题

转义双引号:

 string s = "text'"some text in quotes next text.";
替代:

 string s = @"text""some text in quotes next text.";

因此,如果您收到字符串,或者从xml中解析它,在将其赋值给字符串变量之前,查找双引号并按照上面所述进行转义,例如:

 string s = xmlValue.Replace('"', ''"');