2014-09-24 44 views
0

我在HTML中有基本代碼,我想將此代碼轉換爲字符串格式。我如何將HTML轉換爲字符串。格式

<table id="rounded-corner" summary="2007 Major IT Companies' Profit" style="text-align: center"> 
    <thead> 
     <tr> 
      <th scope="col" class="rounded-company"></th> 
      <th scope="col" class="rounded">Název</th> 
      <th scope="col" class="rounded">Web</th> 
      <th scope="col" class="rounded">Popis</th> 
      <th scope="col" class="rounded">Edit</th> 
      <th scope="col" class="rounded-q4">Delete</th> 
     </tr> 
    </thead> 
    <tbody> 

,我想這HTML使用到的String.format。

StringBuilder data = new StringBuilder(); 
data.Append(string.Format(@"<table id="rounded-corner" summary="2007 Major IT Companies' Profit" style="text-align: center"> 
    <thead> 
     <tr> 
      <th scope="col" class="rounded-company"></th> 
      <th scope="col" class="rounded">Název</th> 
      <th scope="col" class="rounded">Web</th> 
      <th scope="col" class="rounded">Popis</th> 
      <th scope="col" class="rounded">Edit</th> 
      <th scope="col" class="rounded-q4">Delete</th> 
     </tr> 
    </thead> 
    <tbody>")); 

我有問題,這個符號「」對的String.Format,你能幫助我,我怎麼能做到這一點。

+2

只需使用反斜槓即可忽略雙引號。某些行'

' – 2014-09-24 06:47:59

+0

我同意@NayanaAdassuriya .. \指定它不是字符串的結尾。 – 2014-09-24 07:01:26

回答

1

你需要把\"這樣的:

string.Format(@"<table id=\"rounded-corner\" summary=\"2007 Major IT Companies' Profit\" style=\"text-align: center\"> 
    <thead> 
     <tr> 
      <th scope=\"col\" class=\"rounded-company\"></th> 
      <th scope=\"col\" class=\"rounded\">Název</th> 
      <th scope=\"col\" class=\"rounded\">Web</th> 
      <th scope=\"col\" class=\"rounded\">Popis</th> 
      <th scope=\"col\" class=\"rounded\">Edit</th> 
      <th scope=\"col\" class=\"rounded-q4\">Delete</th> 
     </tr> 
    </thead> 
    <tbody>") 

,或者您可以'這樣的:

string.Format(@"<table id='rounded-corner' summary='2007 Major IT Companies Profit' style='text-align: center'> 
     <thead> 
      <tr> 
       <th scope='col' class='rounded-company'></th> 
       <th scope='col' class='rounded'>Název</th> 
       <th scope='col' class='rounded'>Web</th> 
       <th scope='col' class='rounded'>Popis</th> 
       <th scope='col' class='rounded'>Edit</th> 
       <th scope='col' class='rounded-q4'>Delete</th> 
      </tr> 
     </thead> 
     <tbody>") 
+0

thx結果來自你和krisdy是工作thx,但我會用你的結果,因爲它更清晰 – 2014-09-24 07:04:21

0

"的HTML裏面使其""

<table id=""rounded-corner"" summary=""2007 Major IT Companies' Profit"" style=""text-align: center""> 
<thead> 
    <tr> 
     <th scope=""col"" class=""rounded-company""></th> 
     <th scope=""col"" class=""rounded"">Název</th> 
     <th scope=""col"" class=""rounded"">Web</th> 
     <th scope=""col"" class=""rounded"">Popis</th> 
     <th scope=""col"" class=""rounded"">Edit</th> 
     <th scope=""col"" class=""rounded-q4"">Delete</th> 
    </tr> 
</thead> 
<tbody> 
相關問題