public static string InputText(string text)//过滤html,js,css代码
{
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
text = Regex.Replace(text, "[//s]{2,}", " "); //两个或多个空格替换为一个
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); //其它任何标记
text = text.Replace("'", "''");
return text;
}
{
text = text.Trim();
if (string.IsNullOrEmpty(text))
return string.Empty;
text = Regex.Replace(text, "[//s]{2,}", " "); //两个或多个空格替换为一个
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); //其它任何标记
text = text.Replace("'", "''");
return text;
}
本文介绍了一个实用的文本处理方法,通过C#代码实现,主要用于过滤HTML标签、JavaScript及CSS代码,同时对文本进行标准化处理,如空格、换行符及特殊字符的统一替换等。
392

被折叠的 条评论
为什么被折叠?



