1

I have a problem with html formatting in a const string

It is about constructions \"\"\"

        const string reportPosOne =
          $"<table>" +
                  $"<tr style=\"mso-yfti-irow:1\">" +
                    $"<td style=\"width:100px;background:#E9E9E9;padding:.75pt .75pt .75pt .75pt\">" +
                                  $"<p class=MsoNormal><span style=\"font-size:9.5pt;font-family:\"\"MS Sans Serif\"\";color:black\">#Year#<o:p></o:p></span></p>" +
                              $"</td>" +
                           
                   $"</tr>" +
           $"</table>";

Compiler Error CS8400 Feature 'feature' is not available in C# 8.0. Please use language version 10.0 or greater.

earlier it looked like this, but the next method to which I send data requires the sign

"

not

'


        const string reportPos =
            @"<table>
                   <tr style='mso-yfti-irow:1'>
                                      <td style='width:270px;background:#E9E9E9;padding:.75pt .75pt .75pt .75pt'>
                                           <p class=MsoNormal><span style='font-size:9.5pt;font-family:""MS Sans Serif"";color:black'>#Pozycja#<o:p></o:p></span></p>
                                       </td>
                        </tr></table>";
Falcon
  • 59
  • 6
  • Does this answer your question? [Multiline string literal in C#](https://stackoverflow.com/questions/1100260/multiline-string-literal-in-c-sharp) – Yong Shun Dec 21 '21 at 13:48

1 Answers1

2

instead of using string interpolation (via $), just use the string literal method, as you did previously. Instead of using single quotes, use two double quotes instead, the string literal will output it as a single double quote.

const string reportPos =
    @"<table>
        <tr style=""mso-yfti-irow:1"">
            <td style=""width:270px;background:#E9E9E9;padding:.75pt .75pt .75pt .75pt"">
                <p class=MsoNormal><span style=""font-size:9.5pt;font-family:""MS Sans Serif"";color:black"">#Pozycja#<o:p></o:p></span></p>
            </td>
        </tr>
    </table>";

For more information: https://stackoverflow.com/a/1928916/4341083

Kyle
  • 107
  • 7