去除html標(biāo)簽刪除html示例代碼

字號(hào):


    代碼如下:
    /// <summary>
    /// 去除html標(biāo)簽
    /// </summary>
    /// <param name=htmlstring></param>
    /// <returns></returns>
    public static string deletehtml(string htmlstring)
    {
    //刪除html
    htmlstring = regex.replace(htmlstring, @<(.[^>]*)>, , regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @([\r\n])[\s]+, , regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @-->, , regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @<!--.*, , regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&(quot|#34);, \, regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&(amp|#38);, &, regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&(lt|#60);, <, regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&(gt|#62);, >, regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&(nbsp|#160);, , regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&(iexcl|#161);, \xa1, regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&(cent|#162);, \xa2, regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&(pound|#163);, \xa3, regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&(copy|#169);, \xa9, regexoptions.ignorecase);
    htmlstring = regex.replace(htmlstring, @&#(\d+);, , regexoptions.ignorecase);
    htmlstring = htmlstring.replace(<, );
    htmlstring = htmlstring.replace(>, );
    htmlstring = htmlstring.replace(\r\n, );
    return htmlstring;
    }