Home > Software engineering >  html formatting in a const string - Please use language version 10.0 or greater
html formatting in a const string - Please use language version 10.0 or greater

Time:12-22

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

CodePudding user response:

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

  • Related