/// <summary> /// 去除文本中的标签Method to make sure that user's inputs are not malicious /// </summary> /// <param name="text">User's Input</param> /// <param name="maxLength">Maximum length of input</param> /// <returns>The cleaned up version of the input</returns> public static string InputText(string text, int maxLength) { text = text.Trim(); if (string.IsNullOrEmpty(text)) return string.Empty; if (text.Length > maxLength) text = text.Substring(0, maxLength); text = Regex.Replace(text, "[\\s]{2,}", " "); //two or more spaces text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|\\n)*?>)", "\n"); //<br> text = Regex.Replace(text, "(\\s*&[n|N][b|B][s|S][p|P];\\s*)+", " "); // text = Regex.Replace(text, "<(.|\\n)*?>", string.Empty); //any other tags text = text.Replace("'", "''"); return text; } /// <summary> /// Method to check whether input has other characters than numbers /// </summary> public static string CleanNonWord(string text) { return Regex.Replace(text, "\\W", ""); } /// <summary> /// Method to redirect user to search page /// </summary> /// <param name="key">Search keyword</param> public static void SearchRedirect(string key) { HttpContext.Current.Response.Redirect(string.Format(REDIRECT_URL, InputText(key, 255))); } /// <summary> /// Method to retrieve and cache category name by its ID /// </summary> /// <param name="categoryId">Category id</param> /// <returns>Category name</returns> public static string GetCategoryName(string categoryId) { Category category = new Category(); if (!enableCaching) return category.GetCategory(categoryId).Name; string cacheKey = string.Format(CATEGORY_NAME_KEY, categoryId); // Check if the data exists in the data cache string data = (string)HttpRuntime.Cache[cacheKey]; if (data == null) { // Caching duration from Web.config int cacheDuration = int.Parse(ConfigurationManager.AppSettings["CategoryCacheDuration"]); // If the data is not in the cache then fetch the data from the business logic tier data = category.GetCategory(categoryId).Name; // Create a AggregateCacheDependency object from the factory AggregateCacheDependency cd = DependencyFacade.GetCategoryDependency(); // Store the output in the data cache, and Add the necessary AggregateCacheDependency object HttpRuntime.Cache.Add(cacheKey, data, cd, DateTime.Now.AddHours(cacheDuration), Cache.NoSlidingExpiration, CacheItemPriority.High, null); } return data; }
发表评论
-
ipchange
2009-11-23 21:00 663public string ipChange(u ... -
C# excel
2009-09-17 13:09 2169using System; using System. ... -
遍历类的属性
2009-08-12 11:23 743Response.Write(getProperties(l ... -
SqliteHelper
2009-07-27 14:46 1349using System; using Syst ... -
网址收藏
2009-07-23 14:50 701http://www.cnblogs.com/arte ... -
。net常用工具
2009-07-23 14:48 1749ildasm:反编译.net程序; ilasm:编译 ... -
c#生成Excel
2009-07-23 14:45 2544using System;using System.Colle ... -
C#操作Word!
2009-07-23 14:44 3778using System; using System.Com ... -
验证控件网页代码分析2
2009-07-23 14:43 940还有一个子程序是更新整个页面的验证状态: //更新整个页面 ... -
验证控件网页代码分析
2009-07-23 14:38 1532如果我们在文本框中什么都没有输入,直接点击按钮,则激发Butt ... -
ASP.Net 向xml文件中添加数据(insert操作)
2009-07-23 14:33 1009try { ... -
xml操作
2009-07-23 14:32 701using System; using System.Xml ... -
ip地址转换
2009-07-23 14:30 1104public String getIp(long ip10) ... -
BASE64加密解密
2009-07-23 14:28 789string base64EncodeChars = & ... -
winform Splash加载窗口
2009-07-23 14:28 1871static ApplicationContext conte ... -
C#实现快捷键(系统热键)响应
2009-07-23 14:27 1880C#实现快捷键(系统热键)响应 在应用中,我们可能会需要 ... -
WinForm的一些常用技巧
2009-07-23 14:22 2180在任务栏不显示 将WinForm的ShowInT ... -
C#验证码
2009-07-23 14:03 1244using System; using System.Dra ... -
des和RSA两种加密方式的例子
2009-07-23 13:50 1309static public string RSA_Encry ...
相关推荐
SQl去掉HTML标签函数 彻底防止SQL注入
去标签
在获取富文本后,又只要显示部分内容,需要去除富文本标签,然后再截取其中一部分内容;然后就是过滤器,在微信小程序中使用还是挺多次的,在vue及react中也遇到过 1.富文本去除html标签 去除html标签及 空格 let ...
在这个项目中,你将会学习如何使用PyTorch来构建神经网络模型,并结合BERT模型来进行中文文本的多标签分类。 以下是一些步骤和技术细节,可以帮助你开始这个项目: 1. 数据准备:准备一个包含文本数据和对应的多...
一段去除Html页中标签的代码,用法很简单,很实用
提供微信小程序中因为需要展示html富文本文件而出现的问题
通过本文档的加入,可以除去html标签防止于页面标签的冲突从而防止出错
这段代码可以用于去除文本里的字符串标签,不包括标签里面的内容 import re\nhtml='<a href=//www.jb51.net>\u8f6f\u4ef6\u5f00\u53d1\u7f51</a>,Python\u5b66\u4e60\uff01' dr = re.compile(r'<[^>...
asp.net 剔除文本中的html标签 demo,框架 3.5 清除html标记,还原纯文本格式.
简单高效的去除重复文本 1.2 绿色版,去除txt文本里面重复的文本。保存去除后文本,和出现过重复的文本。适用于处理100000以下的文本数据。重复按照文本行计算。即去除重复文本行
java代码-正则去除HTML代码中的IMG标签
python纯文本文件内的html标签
主要介绍了使用正则表达式去除所有html标签只保留文字效果,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友参考下吧
主要介绍了js正则匹配table,img及去除各种标签问题,需要的朋友可以参考下
当我们将网页中的某段文字内容...具体方法是:复制该网页内容后,在新建的Word文档中点击“编辑”,选择“选择性粘贴”,在“选择性粘贴”对话框中选“无格式文本”或“未设格式的Unicode文本”,点击“确定”即可。
分享一个方法,去掉内容里的Html标签,测试数据: DECLARE @str NVARCHAR(max)=' <!DOCTYPE html> <html> <head> </head> <body> 哈哈哈 </body> </html> ' 方法如下:...
/// 已经去除后的文字 public static string NoHTML(string Htmlstring) { //删除脚本 Htmlstring = Regex.Replace(Htmlstring, @"[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); //删除HTML
golang GUI图形界面框架fyne例子 删除html源文档中的html标签