国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

使用C#將HTML文本轉(zhuǎn)換為普通文本,去掉所有的Html標(biāo)記

2019-11-14 10:22:12
字體:
供稿:網(wǎng)友
using System;using System.Collections.Generic;using System.Linq;

using System.Text;

//首先需要導(dǎo)入命名空間using System.Text.RegularExPRessions;namespace WindowsFormsapplication1{   public class Class1    {       /// <summary>       /// 將html文本轉(zhuǎn)化為 文本內(nèi)容方法NoHTML       /// </summary>       /// <param name="Htmlstring">HTML文本值</param>       /// <returns></returns>        public string NoHTML(string Htmlstring)        {            //刪除腳本               Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);            //刪除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);            //替換掉 < 和 > 標(biāo)記            Htmlstring.Replace("<", "");            Htmlstring.Replace(">", "");            Htmlstring.Replace("/r/n", "");            //返回去掉html標(biāo)記的字符串            return Htmlstring;        }    }}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 方山县| 汶川县| 阳城县| 黄龙县| 改则县| 西畴县| 永年县| 延津县| 阿图什市| 天等县| 文安县| 瑞昌市| 盐亭县| 临潭县| 房产| 广平县| 西安市| 临洮县| 遂溪县| 栾城县| 邯郸市| 类乌齐县| 南昌县| 岳阳市| 建瓯市| 利辛县| 顺义区| 铜川市| 清河县| 绍兴市| 潼关县| 万荣县| 游戏| 河东区| 宣化县| 呼和浩特市| 札达县| 米泉市| 松潘县| 偏关县| 大冶市|