简体   繁体   English

带有转义双引号的语法错误

[英]Syntax error with Escaping double quotes

tw.WriteLine(@" ""Air Temperature sensor "" 20," + measure + ", 24, """ + this.time.Year + "-" + this.time.Month + "-" + this.time.Day + " " + this.time.Hour + ":" + this.time.Minute + ":" + this.time.Second + "\"");

When I have three double quotes is call me I have Syntax error, ',' expected I try with four double quotes, with slash but again I have this error. 当我给三个双引号打电话时,我有语法错误“,”,我应该尝试使用四个双引号和斜线,但是我又遇到了这个错误。 I know for escaping double quotes is need two double quotes. 我知道转义双引号需要两个双引号。 But for my case is not working. 但对我而言,这是行不通的。

As per msdn, you will either use @"" or escape with \\" 根据msdn,您将使用@“”或使用\\“转义

https://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx https://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx

For what you are trying to achieve, the best approach is using string.Format , as follows: 对于您要实现的目标,最好的方法是使用string.Format ,如下所示:

string.Format(@"""Air Temperature sensor "" 20, {0}, 24 "" {1:yyyy-MM-dd hh:mm:ss}", measure, this.time);

You don't need to build the date taking the single properties when .NET can format it for you. 当.NET可以为您设置日期格式时,您无需构建具有单个属性的日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM