<table style="WIDTH: 458pt; BORDER-COLLAPSE: collapse" cellspacing="0" cellpadding="0" width="610" border="0">  <colgroup>  
<col style="WIDTH: 113pt; mso-width-source: userset; mso-width-alt: 4800" width="150">  <col style="WIDTH: 345pt; mso-width-source: userset; mso-width-alt: 14720" width="460">  <tbody> 
 <tr style="HEIGHT: 15.75pt" height="21">  <td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 113pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 15.75pt; BACKGROUND-COLOR: silver" width="150" height="21"><strong>General Spec</strong></td>  <td class="xl25" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 345pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: silver" width="460"><strong> </strong></td></tr>  
<tr style="HEIGHT: 14.25pt; mso-height-source: userset" height="19">  <td class="xl24" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent" height="19">Color</td>  <td class="xl24" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">black</td></tr>  
<tr style="HEIGHT: 14.25pt; mso-height-source: userset" height="19">  <td class="xl24" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent" height="19">Function</td>  <td class="xl24" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent">provide high speed USB2.0 data transferring</td></tr> 
 <tr style="HEIGHT: 14.25pt; mso-height-source: userset" height="19">  <td class="xl24" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent" height="19">Compatibility</td>  <td class="xl26" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 345pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent" width="460">iPhone/Nokia/Blackberry/HTC Cell Phones, etc.</td></tr> 
 <tr style="HEIGHT: 15.75pt" height="21">  <td class="xl27" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15.75pt; BACKGROUND-COLOR: silver" colspan="2" height="21"><strong>Features</strong></td></tr>  
<tr style="HEIGHT: 41.25pt; mso-height-source: userset" height="55">  <td class="xl28" style="BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 458pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 41.25pt; BACKGROUND-COLOR: transparent" width="610" colspan="2" height="55">Provide high speed USB2.0 data transfers while charging your cell phone through the USB interface.<br />Cable pro for iPod, iPhone and iPhone 3G/3Gs.<br />Cable pro for Nokia 5630 Xpress music, 6500 classic, 7900 prism, 8600 luna, 8800 arte, 8800 carbon arte, N85, N97 etc.<br />Cable pro for Blackberry 7230, 7290, 8100, 8120, 8110, 8130, 8300 etc.<br />Cable pro for hero, magic, dream, touch, diamond, advantage, shift, TyTn etc.</td>
</tr>
</tbody>
</table>
<br />我想对上面的串去掉所有html标签,但是这个有个要求就是每当</tr>的时候替换成" 。" 句话  ,全部替换网上找了个正则,但是替换的时候判断如果是</tr>就换成句话,用c#怎么实现,高手帮帮忙

解决方案 »

  1.   


    String str =
                    @"<table style=""WIDTH: 458pt; BORDER-COLLAPSE: collapse"" cellspacing=""0"" cellpadding=""0"" width=""610"" border=""0"">  <colgroup>  
    <col style=""WIDTH: 113pt; mso-width-source: userset; mso-width-alt: 4800"" width=""150"">  <col style=""WIDTH: 345pt; mso-width-source: userset; mso-width-alt: 14720"" width=""460"">  <tbody> 
     <tr style=""HEIGHT: 15.75pt"" height=""21"">  <td class=""xl25"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 113pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 15.75pt; BACKGROUND-COLOR: silver"" width=""150"" height=""21""><strong>General Spec</strong></td>  <td class=""xl25"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 345pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: silver"" width=""460""><strong> </strong></td></tr>  
    <tr style=""HEIGHT: 14.25pt; mso-height-source: userset"" height=""19"">  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent"" height=""19"">Color</td>  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"">black</td></tr>  
    <tr style=""HEIGHT: 14.25pt; mso-height-source: userset"" height=""19"">  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent"" height=""19"">Function</td>  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"">provide high speed USB2.0 data transferring</td></tr> 
     <tr style=""HEIGHT: 14.25pt; mso-height-source: userset"" height=""19"">  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent"" height=""19"">Compatibility</td>  <td class=""xl26"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 345pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"" width=""460"">iPhone/Nokia/Blackberry/HTC Cell Phones, etc.</td></tr> 
     <tr style=""HEIGHT: 15.75pt"" height=""21"">  <td class=""xl27"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15.75pt; BACKGROUND-COLOR: silver"" colspan=""2"" height=""21""><strong>Features</strong></td></tr>  
    <tr style=""HEIGHT: 41.25pt; mso-height-source: userset"" height=""55"">  <td class=""xl28"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 458pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 41.25pt; BACKGROUND-COLOR: transparent"" width=""610"" colspan=""2"" height=""55"">Provide high speed USB2.0 data transfers while charging your cell phone through the USB interface.<br />Cable pro for iPod, iPhone and iPhone 3G/3Gs.<br />Cable pro for Nokia 5630 Xpress music, 6500 classic, 7900 prism, 8600 luna, 8800 arte, 8800 carbon arte, N85, N97 etc.<br />Cable pro for Blackberry 7230, 7290, 8100, 8120, 8110, 8130, 8300 etc.<br />Cable pro for hero, magic, dream, touch, diamond, advantage, shift, TyTn etc.</td>
    </tr>
    </tbody>
    </table>
    <br />";
                String noTr = str.Replace("</tr>", "。");
                String result = Regex.Replace(noTr, "<[^>]+>", "");
                Console.Write(result);结果:
       General Spec   。  
      Color  black。  
      Function  provide high speed USB2.0 data transferring。 
       Compatibility  iPhone/Nokia/Blackberry/HTC Cell Phones, etc.。 
       Features。  
      Provide high speed USB2.0 data transfers while charging your cell phone through the USB interface.Cable pro for iPod, iPhone and iPhone 3G/3Gs.Cable pro for Nokia 5630 Xpress music, 6500 classic, 7900 prism, 8600 luna, 8800 arte, 8800 carbon arte, N85, N97 etc.Cable pro for Blackberry 7230, 7290, 8100, 8120, 8110, 8130, 8300 etc.Cable pro for hero, magic, dream, touch, diamond, advantage, shift, TyTn etc.
      

  2.   

        public void Test()
        {
            string html = @"<table style=""WIDTH: 458pt; BORDER-COLLAPSE: collapse"" cellspacing=""0"" cellpadding=""0"" width=""610"" border=""0"">  <colgroup>  
    <col style=""WIDTH: 113pt; mso-width-source: userset; mso-width-alt: 4800"" width=""150"">  <col style=""WIDTH: 345pt; mso-width-source: userset; mso-width-alt: 14720"" width=""460"">  <tbody> 
     <tr style=""HEIGHT: 15.75pt"" height=""21"">  <td class=""xl25"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 113pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 15.75pt; BACKGROUND-COLOR: silver"" width=""150"" height=""21""><strong>General Spec</strong></td>  <td class=""xl25"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 345pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: silver"" width=""460""><strong> </strong></td></tr>  
    <tr style=""HEIGHT: 14.25pt; mso-height-source: userset"" height=""19"">  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent"" height=""19"">Color</td>  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"">black</td></tr>  
    <tr style=""HEIGHT: 14.25pt; mso-height-source: userset"" height=""19"">  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent"" height=""19"">Function</td>  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"">provide high speed USB2.0 data transferring</td></tr> 
     <tr style=""HEIGHT: 14.25pt; mso-height-source: userset"" height=""19"">  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent"" height=""19"">Compatibility</td>  <td class=""xl26"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 345pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"" width=""460"">iPhone/Nokia/Blackberry/HTC Cell Phones, etc.</td></tr> 
     <tr style=""HEIGHT: 15.75pt"" height=""21"">  <td class=""xl27"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15.75pt; BACKGROUND-COLOR: silver"" colspan=""2"" height=""21""><strong>Features</strong></td></tr>  
    <tr style=""HEIGHT: 41.25pt; mso-height-source: userset"" height=""55"">  <td class=""xl28"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 458pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 41.25pt; BACKGROUND-COLOR: transparent"" width=""610"" colspan=""2"" height=""55"">Provide high speed USB2.0 data transfers while charging your cell phone through the USB interface.<br />Cable pro for iPod, iPhone and iPhone 3G/3Gs.<br />Cable pro for Nokia 5630 Xpress music, 6500 classic, 7900 prism, 8600 luna, 8800 arte, 8800 carbon arte, N85, N97 etc.<br />Cable pro for Blackberry 7230, 7290, 8100, 8120, 8110, 8130, 8300 etc.<br />Cable pro for hero, magic, dream, touch, diamond, advantage, shift, TyTn etc.</td>
    </tr>
    </tbody>
    </table>
    <br />";
            string result = Regex.Replace(html, @"<([^<>\s]+)[^>]*>", delegate(Match m) { return string.Compare(m.Groups[1].Value, "/tr", true)==0 ? "。" : ""; });
            Console.WriteLine(result);
        }
      

  3.   

            string str = "这里是你原始字符串";
            str = str.Replace("</tr>", "。");
            Regex objRegExp = new Regex("<(.|\n)+?>");
            str = objRegExp.Replace(str, "");
            str = str.Replace("<", "");
            str = str.Replace(">", "");
      

  4.   

    可以这样来写:void Main()
    {

    String str = @"<table style=""WIDTH: 458pt; BORDER-COLLAPSE: collapse"" cellspacing=""0"" cellpadding=""0"" width=""610"" border=""0"">  <colgroup>  
    <col style=""WIDTH: 113pt; mso-width-source: userset; mso-width-alt: 4800"" width=""150"">  <col style=""WIDTH: 345pt; mso-width-source: userset; mso-width-alt: 14720"" width=""460"">  <tbody> 
     <tr style=""HEIGHT: 15.75pt"" height=""21"">  <td class=""xl25"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 113pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 15.75pt; BACKGROUND-COLOR: silver"" width=""150"" height=""21""><strong>General Spec</strong></td>  <td class=""xl25"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 345pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: silver"" width=""460""><strong> </strong></td></tr>  
    <tr style=""HEIGHT: 14.25pt; mso-height-source: userset"" height=""19"">  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent"" height=""19"">Color</td>  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"">black</td></tr>  
    <tr style=""HEIGHT: 14.25pt; mso-height-source: userset"" height=""19"">  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent"" height=""19"">Function</td>  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"">provide high speed USB2.0 data transferring</td></tr> 
     <tr style=""HEIGHT: 14.25pt; mso-height-source: userset"" height=""19"">  <td class=""xl24"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 14.25pt; BACKGROUND-COLOR: transparent"" height=""19"">Compatibility</td>  <td class=""xl26"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 345pt; BORDER-BOTTOM: #ece9d8; BACKGROUND-COLOR: transparent"" width=""460"">iPhone/Nokia/Blackberry/HTC Cell Phones, etc.</td></tr> 
     <tr style=""HEIGHT: 15.75pt"" height=""21"">  <td class=""xl27"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; BORDER-BOTTOM: #ece9d8; HEIGHT: 15.75pt; BACKGROUND-COLOR: silver"" colspan=""2"" height=""21""><strong>Features</strong></td></tr>  
    <tr style=""HEIGHT: 41.25pt; mso-height-source: userset"" height=""55"">  <td class=""xl28"" style=""BORDER-RIGHT: #ece9d8; BORDER-TOP: #ece9d8; BORDER-LEFT: #ece9d8; WIDTH: 458pt; BORDER-BOTTOM: #ece9d8; HEIGHT: 41.25pt; BACKGROUND-COLOR: transparent"" width=""610"" colspan=""2"" height=""55"">Provide high speed USB2.0 data transfers while charging your cell phone through the USB interface.<br />Cable pro for iPod, iPhone and iPhone 3G/3Gs.<br />Cable pro for Nokia 5630 Xpress music, 6500 classic, 7900 prism, 8600 luna, 8800 arte, 8800 carbon arte, N85, N97 etc.<br />Cable pro for Blackberry 7230, 7290, 8100, 8120, 8110, 8130, 8300 etc.<br />Cable pro for hero, magic, dream, touch, diamond, advantage, shift, TyTn etc.</td>
    </tr>
    </tbody>
    </table>
    <br />";
    String noTr = str.Replace("</tr>", "。");
    String result = Regex.Replace(noTr, "<[^>]+>",(Match m)=>m.Value=="</tr>"?"。":"");
    Console.Write(result);
    }
      

  5.   

      String noTr = str.Replace("</tr>", "。");
                String result = Regex.Replace(noTr, "<[^>]+>", "");
                Console.Write(result);
    简单,易懂.
      

  6.   

    囧~~String result = Regex.Replace(str, "<[^>]+>",(Match m)=>m.Value=="</tr>"?"。":"");
      

  7.   

    既然lambda了。就彻底点好了。类型让编译器自己判断了。
    String result = Regex.Replace(str, "<[^>]+>",m=>m.Value=="</tr>"?"。":"");