[JF:loop JF:ChannelID=25,JF:NewsType=pic,JF:NewsCount=2,JF:TitleNum=3,JF:Cols=1,JF:Width=100%,JF:Keyword=秀,JF:NewsDate=2007-10-02]<TR><TD width=\"276\" height=\"20\">· <a href=\"[JF:NewsPath]\" target=\"_blank\">[JF:Title]</a></TD></TR>
[/JF:loop]
问题就是把上面[JF:loop JF:ChannelID=25,JF:NewsType=pic,JF:NewsCount=2,JF:TitleNum=3,JF:Cols=1,JF:Width=100%,JF:Keyword=秀,JF:NewsDate=2007-10-02]这段代码和结尾处的[/JF:loop]代码替换为空

解决方案 »

  1.   

    好象就是去掉html代码类似我也不会写,从网络上找了点资料你自己改吧public string ClearHtml(string strHtml)
    {
    string [] aryReg ={
      @"<script[^>]*?>.*?</script>",
      @"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>",
      @"([\r\n])[\s]+",
      @"&(quot|#34);",
      @"&(amp|#38);",
      @"&(lt|#60);",
      @"&(gt|#62);",
      @"&(nbsp|#160);",
      @"&(iexcl|#161);",
      @"&(cent|#162);",
      @"&(pound|#163);",
      @"&(copy|#169);",
      @"&#(\d+);",
      @"-->",
      @"<!--.*\n"   };
    string [] aryRep = {
       "",
       "",
       "",
       "\"",
       "&",
       "<",
       ">",
       " ",
       "\xa1",//chr(161),
       "\xa2",//chr(162),
       "\xa3",//chr(163),
       "\xa9",//chr(169),
       "",
       "\r\n",
       ""
       };
    string newReg =aryReg[0];
    string strOutput=strHtml;
    for(int i = 0;i<aryReg.Length;i++)
    {
    Regex regex = new Regex(aryReg[i],RegexOptions.IgnoreCase );
    strOutput = regex.Replace(strOutput,aryRep[i]);
    }
    strOutput.Replace("<","");
    strOutput.Replace(">","");
    strOutput.Replace("\r\n","");
    strOutput.Replace("&nbsp;","");
    strOutput.Replace("&nbsp","");
    // strOutput.Replace("&nb","");
    strOutput.Replace(" ","");
    return "&nbsp;&nbsp;"+strOutput;
    }
      

  2.   

    如果这么死,直接字符串替换不就行了?假设你要的是替换"[JF:loop ...]"和"[/JF:loop]",那么正则:@"\[JF:loop [\]]*\]|\[/JF:loop\]"
      

  3.   

    string yourStr = ......;
    yourStr = Regex.Replace(yourStr, "\\[jf:loop.+?\\]([\\s|\\S]+?)\\[/jf:loop\\]", "$1", RegexOptions.IgnoreCase);