求一过虑字符串中HTML标签及特殊符号的方法(asp.net)
要求写一个.cs方法publicstringEncodeStr(stringstr){return//处理后字符串;}...
要求写一个.cs方法
public string EncodeStr(string str){
return //处理后字符串;
} 展开
public string EncodeStr(string str){
return //处理后字符串;
} 展开
4个回答
2013-06-29
展开全部
using System;
/// <summary>
/// CleanString 的摘要说明。
/// </summary>
public sealed class CleanString
{
public static string htmlInputText( string inputString )//HTML过滤输入字符串
{
if ((inputString != null) && (inputString != String.Empty ))
{
inputString = inputString.Trim();
inputString = inputString.Replace("'",""");
inputString = inputString.Replace("<","<");
inputString = inputString.Replace(">",">");
inputString = inputString.Replace(" "," ");
inputString = inputString.Replace("\n","<br>");
return inputString.ToString();
}
return "";
}
public static string htmlOutputText( string inputString )//HTML还原字符串
{
if ((inputString != null) && (inputString != String.Empty ))
{
inputString = inputString.Trim();
inputString = inputString.Replace(""","'");
inputString = inputString.Replace("<","<");
inputString = inputString.Replace(">",">");
inputString = inputString.Replace(" "," ");
inputString = inputString.Replace("<br>","\n");
return inputString.ToString();
}
return "";
}
}
把这个写成一个类 想在哪里用随便掉就好了!很方便的...!
/// <summary>
/// CleanString 的摘要说明。
/// </summary>
public sealed class CleanString
{
public static string htmlInputText( string inputString )//HTML过滤输入字符串
{
if ((inputString != null) && (inputString != String.Empty ))
{
inputString = inputString.Trim();
inputString = inputString.Replace("'",""");
inputString = inputString.Replace("<","<");
inputString = inputString.Replace(">",">");
inputString = inputString.Replace(" "," ");
inputString = inputString.Replace("\n","<br>");
return inputString.ToString();
}
return "";
}
public static string htmlOutputText( string inputString )//HTML还原字符串
{
if ((inputString != null) && (inputString != String.Empty ))
{
inputString = inputString.Trim();
inputString = inputString.Replace(""","'");
inputString = inputString.Replace("<","<");
inputString = inputString.Replace(">",">");
inputString = inputString.Replace(" "," ");
inputString = inputString.Replace("<br>","\n");
return inputString.ToString();
}
return "";
}
}
把这个写成一个类 想在哪里用随便掉就好了!很方便的...!
2013-06-29
展开全部
不需要过滤,Asp.net中有个repeter控件,使用它的好处是就是去除了HTML标签,不会生成它,至于他的用法你可以在网上查下,这一下子说不清楚
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-29
展开全部
用server.HtmlEncode("脚本代码")
可以把客户端输入的脚本代码,原样显示不执行!
可以把客户端输入的脚本代码,原样显示不执行!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-06-29
展开全部
你的意识是过滤 特殊符号 还有HTML标签吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询