0

In one of my datatable column, I want the value to be shown in double quotes

AS:- "My value"

Below is my code:-

 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 />";

I want to show REMARK value in double quotes.

How to achieve that ?

INDIA IT TECH
  • 1,902
  • 4
  • 12
  • 25
Nad
  • 4,605
  • 11
  • 71
  • 160

3 Answers3

2

Add extra quotes with backslash:

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 />";
Orkun Bekar
  • 1,447
  • 1
  • 15
  • 36
1

Use \ to print the escape sequence characters in a string

 " with Remark <b> \"" + table.Rows[0]["REMARKS"] + "\" </b><br /><br />";
M.S.
  • 4,283
  • 1
  • 19
  • 42
0

For better readability I would use verbatim string literal, as it allows to avoid concatenation and easily expand on multiple lines. Also, String.Format would make your string more readable:

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"]);

Also, C# 6.0 (Visual Studio 2015) has introduced interpolated strings, that makes string construction even more reader friendly:

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 />";
Community
  • 1
  • 1
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164