转义双引号的语法错误
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 + "\"");
当我有三个双引号时,请告诉我我有 语法错误,',' 预期 我尝试使用四个双引号和斜杠,但我再次遇到此错误。我知道转义双引号需要两个双引号。但对我来说是行不通的。
根据 msdn,您将使用 @"" 或使用 \"
转义
https://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx
对于您要实现的目标,最好的方法是使用 string.Format
,如下所示:
string.Format(@"""Air Temperature sensor "" 20, {0}, 24 "" {1:yyyy-MM-dd hh:mm:ss}", measure, this.time);
当 .NET 可以为您设置格式时,您无需构建具有单一属性的日期。
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 + "\"");
当我有三个双引号时,请告诉我我有 语法错误,',' 预期 我尝试使用四个双引号和斜杠,但我再次遇到此错误。我知道转义双引号需要两个双引号。但对我来说是行不通的。
根据 msdn,您将使用 @"" 或使用 \"
转义https://msdn.microsoft.com/en-us/library/aa691090(v=vs.71).aspx
对于您要实现的目标,最好的方法是使用 string.Format
,如下所示:
string.Format(@"""Air Temperature sensor "" 20, {0}, 24 "" {1:yyyy-MM-dd hh:mm:ss}", measure, this.time);
当 .NET 可以为您设置格式时,您无需构建具有单一属性的日期。