1.StringBuilder这个东西在调试的时候,如果过长就只显示一半,我还以为是长度限制,郁闷半天╮(╯▽╰)╭

2.xml有5个特殊字符串要过滤的

代码
       #region xml字符转义
        
public static string ReplaceESC(string str)
        {
            
return str.Replace("&""&amp;").Replace("&nbsp;"" ").Replace("<""&lt;").Replace(">""&gt;").Replace("'""&apos;").Replace("\"""&quot;");
        }
        
#endregion


 3.declare @da datetime
set @da ='2001-02-12'
select dateadd(DAY,1,@da) 添加一天,具体用法如下

  select   IndexID  from Tab_CollectComment  
       where   CommentDate between  @BeginDate  and  dateadd(DAY,1,@BeginDate  )
 

4。C#判断时间段

 

 

代码
   public static Boolean DateInBeginEnd(string now, string begin, string end)
        {
            
if (DateTime.Now > DateTime.Parse(begin) && DateTime.Now < DateTime.Parse(end))
            {
                
return true;//再此时间段
            }
            
return false;
        }

 

 

5。C#操作cookie

    #region 操作Cookie
   
        public static void SetCookie(string CookieName, string CookieValue)
        {
            CookieValue = Encrypt(CookieValue);
            System.Web.HttpContext.Current.Response.Cookies[CookieName].Value = CookieValue;
            //System.Web.HttpContext.Current.Response.Cookies[CookieName].Domain = "it168.com";
        }
        public static void SetCookie(string CookieName, string CookieValue, DateTime ExpireTime)
        {
            System.Web.HttpContext.Current.Response.Cookies[CookieName].Expires = ExpireTime;
            SetCookie(CookieName, CookieValue);
        }

        /// 读取加密过的COOKIE
        public static string GetCookie(string CookieName)
        {
            string CookieValue = null;
            if (System.Web.HttpContext.Current.Request.Cookies[CookieName] != null)
            {
                CookieValue = Decrypt(System.Web.HttpContext.Current.Request.Cookies[CookieName].Value);
            }
            return CookieValue;
        }

        /// 删除COOKIE
        public static void DelCookie(string CookieName)
        {
            SetCookie(CookieName, "", DateTime.Now.AddYears(-1));
        }
        #endregion

 

代码
        #region 过滤掉字符串中所有html元素
        
public static string CutAllHtmlElement(string InputStr)
        {
            
return Regex.Replace(InputStr, @"<[^>]+>""");
        }
        
public static string CutAllHtmlElement_All(string InputStr)
        {
            
return Regex.Replace(InputStr, @"<([\s\S]*?)>""");
        }
        
#endregion
代码
        #region 过滤html中危险标签
        
public static string CutDangerousHtmlElement(string html)
        {
            System.Text.RegularExpressions.Regex regex1 
= new System.Text.RegularExpressions.Regex(@"<script[^>]*>[^>]*<[^>]script[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            
//System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            
//System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[^>]*>[^>]*<[^>]iframe[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex5 
= new System.Text.RegularExpressions.Regex(@"<frameset[^>]*>[^>]*<[^>]frameset[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex6 
= new System.Text.RegularExpressions.Regex(@"<img (.+?) />", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            html 
= regex1.Replace(html, ""); //过滤<script></script>标记  
            
//html = regex2.Replace(html, ""); //过滤href=javascript: (<a>) 属性  
            
//html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件  
            html = regex4.Replace(html, ""); //过滤iframe  
            html = regex5.Replace(html, ""); //过滤frameset 

            html 
= regex6.Replace(html, "<img  " + "${1}" + " />");

            
return html;
        }
        
#endregion


 

代码
        #region 计算两个日期的时间间隔
        
/// <summary>
        
/// 计算两个日期的时间间隔
        
/// </summary>
        
/// <param name="DateTime1">第一个日期和时间</param>
        
/// <param name="DateTime2">第二个日期和时间</param>
        
/// <returns></returns>
        public static int DateDiff(DateTime DateTime1, DateTime DateTime2, int flag)
        {
            
int dateDiff = 0;

            TimeSpan ts1 
= new TimeSpan(DateTime1.Ticks);
            TimeSpan ts2 
= new TimeSpan(DateTime2.Ticks);
            TimeSpan ts 
= ts1.Subtract(ts2);
            dateDiff 
= //ts.Days.ToString() + "天"
                
// + ts.Hours.ToString() + "小时"
                
//+ ts.Minutes.ToString() + "分钟"
                ts.Seconds; //+ "秒";
            if (flag == 1)
            {
                dateDiff 
= ts.Hours;
            }
            
else if (flag == 2)
            {
                dateDiff 
= ts.Days;
            }
            
return dateDiff;
        }
        
#endregion

判断是中文

代码
        #region 判断是中文
        
/// <summary>
        
/// 判断是中文
        
/// </summary>
        
/// <param name="input"></param>
        
/// <returns></returns>
        public static bool IsChineseLetter(string input)
        {
            
bool isChineseLetter = false;
            
if (!string.IsNullOrEmpty(input))
            {
                
int bC = 0;
                
for (int i = 0; i < input.Length; i++)
                {
                    Regex rx 
= new Regex("^[\u4e00-\u9fa5]$");
                    
if (rx.IsMatch(input[i].ToString()))
                    {
                        bC
++;
                    }
                }
                
if (bC == 0)
                    isChineseLetter 
= false;
                
else
                    isChineseLetter 
= true;
            }
            
else
            {
                isChineseLetter 
= false;
            }
            
return isChineseLetter;
        }
        
#endregion


 XML 字符转义

 

代码
        #region xml字符转义
        
public static string ReplaceESC(string str)
        {
            
return str.Replace("&""&amp;").Replace("&nbsp;"" ").Replace("<""&lt;").Replace(">""&gt;").Replace("'""&apos;").Replace("\"""&quot;");
        }
        
#endregion
 

 

 

 

HTML字符转义

 

代码
 
        
#region html字符转义
        
public static string HtmlFilter(string str)
        { 
            
return str.Replace("&""&amp;").Replace("<""&lt;").Replace(">""&gt;").Replace("\"""&quot;");
        }
        
#endregion

 

 

posted on 2010-06-18 11:24  wsenmin  阅读(592)  评论(0编辑  收藏  举报