.net中让LABEL接受的文本自动分行并且过滤多余的字符或者恶意字符
/// <summary>
/// 让LABEL接受的文本自动分行并且过滤多余的字符或者恶意字符
/// </summary>
/// <param name="inputString"></param>
/// <returns></returns>
public static string ConvertStr(string inputString)//定义
{
string retVal=inputString;
retVal=retVal.Replace("&","&"); //过滤字符&
// retVal=retVal.Replace("\"","""); //过滤字符\
// retVal=retVal.Replace("<","<"); //过滤字符<
// retVal=retVal.Replace(">",">"); //过滤字符>
// retVal=retVal.Replace(" "," "); //过滤字符空格" "
// retVal=retVal.Replace(" "," "); //过滤字符" "" "
// retVal=retVal.Replace("\t"," ");//过滤字符\t
retVal=retVal.Replace("\r", "<br>");//过滤字符\r<br>
return retVal;
}
public static string ToUrl(string inputString)//引用并替换
{
string retVal=inputString;
retVal= ConvertStr(retVal);
return retVal;
// retVal= Regex.Replace(retVal,@"\[url](?<x>[^\]]*)\[/url]",@"<a href=""$1"" target=""_blank"">$1</a>",RegexOptions.IgnoreCase);
// retVal= Regex.Replace(retVal,@"\[flash=(?<width>\d+),(?<height>\d+)](?<x>[^\]]*)\[/flash]",@"<embed src=""$3"" width=""${width}"" height=""${height}""></embed>",RegexOptions.IgnoreCase);
// retVal= Regex.Replace(retVal,@"\[flash](?<x>[^\]]*)\[/flash]",@"<embed src=""$1""></embed>",RegexOptions.IgnoreCase);
// return Regex.Replace(retVal,@"\[img](?<x>[^\]]*)\[/img]",@"<a href=""$1"" target=""_blank""><img src=""$1"" onload=""javascript:if(this.width>screen.width-220)this.width=screen.width-220"" border=1></a>",RegexOptions.IgnoreCase);
}