将双引号添加到数据表列

时间:2016-03-30 11:16:08

标签: c# asp.net datatable

在我的datatable列之一中,我希望该值以双引号显示

AS: - "My value"

以下是我的代码: -

 string StrPriBody = "Dear User, <br><br> The Number of days revised by you from " +
     " " + table.Rows[0]["LAST_ACTION_DAYS"] + " days to " +
     " " + table.Rows[0]["CURRENT_ACTION_DAYS"] + " days. <br /> " +
     " with Remark <b> " + table.Rows[0]["REMARKS"] + "</b><br /><br />";
  

我想用双引号显示REMARK值。

如何实现?

3 个答案:

答案 0 :(得分:2)

使用反斜杠添加额外的引号:

string StrPriBody = "Dear User, <br><br> The Number of days revised by you from " +
     " " + table.Rows[0]["LAST_ACTION_DAYS"] + " days to " +
     " " + table.Rows[0]["CURRENT_ACTION_DAYS"] + " days. <br /> " +
     " with Remark <b> \"" + table.Rows[0]["REMARKS"] + "\"</b><br /><br />";

答案 1 :(得分:1)

使用\在字符串中打印转义序列字符

Read a

答案 2 :(得分:0)

为了更好的可读性,我会使用verbatim string literal,因为它允许避免连接并轻松扩展多行。此外,String.Format会使您的字符串更具可读性:

string StrPriBody = String.Format(@"
Dear User, 
<br><br> 
The Number of days revised by you from {0} days to {1} days. <br />
with Remark <b> ""{2}""</b>
<br /><br />",
   table.Rows[0]["LAST_ACTION_DAYS"],
   table.Rows[0]["CURRENT_ACTION_DAYS"],
   table.Rows[0]["REMARKS"]);

此外,C#6.0(Visual Studio 2015)引入了interpolated strings,这使得字符串构造更加便于阅读:

string StrPriBody = $@"
Dear User, 
<br><br> 
The Number of days revised by you from {table.Rows[0]["LAST_ACTION_DAYS"]} days to {table.Rows[0]["CURRENT_ACTION_DAYS"]} days. <br />
with Remark <b> ""{table.Rows[0]["REMARKS"]}""</b>
<br /><br />";