", CHR(10)) HTMLDecode = StrEnd IfEnd Function'去掉html标签,去掉换行Function NoHtml(strText) Dim regEx Set regEx = New RegExp regEx.Global = True regEx.IgnoreCase = True regEx.Pattern = "\n" strText = regEx.Replace(strText,"") regEx.Pattern = "\r" strText = regEx.Replace(strText,"") regEx.Pattern = "(.*?)<\/scrīpt>" strText = regEx.Replace(strText,"") regEx.Pattern = "<(.+?)>" strText = regEx.Replace(strText,"")NoHtml = strTextEnd Function function strcurrency(str)str=mid(cstr(formatcurrency(str,2)),2) strcurrency=str end function
没有几种.原理就是删掉正则匹配到的html标签
至于删除用repalce还是remove我觉得没那么重要了就..
html标签的正则,网上抄的不知道对不对:
"<(.[^>]*)>"
public static string NoHtml(string text){
//删除脚本
text = Regex.Replace(text, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase)
//删除HTML
text = Regex.Replace(text, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"-->", "", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"<!--.*", "", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"&(quot|#34)", "\"", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"&(amp|#38)", "&", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"&(lt|#60)", "<", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"&(gt|#62)", ">", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"&(nbsp|#160)", " ", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"&(iexcl|#161)", "\xa1", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"&(cent|#162)", "\xa2", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"&(pound|#163)", "\xa3", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"&(copy|#169)", "\xa9", RegexOptions.IgnoreCase)
text = Regex.Replace(text, @"(\d+)", "", RegexOptions.IgnoreCase)
text.Replace("<", "")
text.Replace(">", "")
text.Replace("\r\n", "")
text = HttpContext.Current.Server.HtmlEncode(text).Trim()
return text
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)