专注于技术经验交流

水至清则无鱼、宁静而致远!

技术、经验、学习共同打造网络新生活!
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理


lbnr.Text=ToUrl(dr["Remark"].ToString());//具体到某个控件的text显示的内容引用


/// <summary>
  /// 让LABEL接受的文本自动分行并且过滤多余的字符或者恶意字符
  /// </summary>
  /// <param name="inputString"></param>
  /// <returns></returns>
  public static string ConvertStr(string inputString)//定义
  {
   string retVal=inputString;
   retVal=retVal.Replace("&","&amp;"); //过滤字符&
//   retVal=retVal.Replace("\"","&quot;"); //过滤字符\
//   retVal=retVal.Replace("<","&lt;"); //过滤字符<
//   retVal=retVal.Replace(">","&gt;"); //过滤字符>
//   retVal=retVal.Replace(" ","&nbsp;"); //过滤字符空格" "
//   retVal=retVal.Replace("  ","&nbsp;&nbsp;"); //过滤字符" "" "
//   retVal=retVal.Replace("\t","&nbsp;&nbsp;");//过滤字符\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);
  }
  

New Document