过滤非法字符

/// <summary>
        /// 过滤特殊字符
        /// 如果字符串为空,直接返回。
        /// </summary>
        /// <param name="str">需要过滤的字符串</param>
        /// <returns>过滤好的字符串</returns>
        //过滤非法字符
    public static string FilterSpecial(string str)
    {
        if (str == "")
        {
            return str;
        }
        else
        {
            str = str.Replace("'", "");
            str = str.Replace("<", "");
            str = str.Replace(">", "");
            str = str.Replace("%", "");
            str = str.Replace("'delete", "");
            str = str.Replace("'drop", "");
            str = str.Replace("'alter","");
            str = str.Replace("'add","");
            str = str.Replace("''", "");
            str = str.Replace("\"\"", "");
            str = str.Replace(",", "");
            str = str.Replace(".", "");
            str = str.Replace(">=", "");
            str = str.Replace("=<", "");
            str = str.Replace("-", "");
            str = str.Replace("_", "");
            str = str.Replace(";", "");
            str = str.Replace("||", "");
            str = str.Replace("[", "");
            str = str.Replace("]", "");
            str = str.Replace("&", "");
            str = str.Replace("#", "");
            str = str.Replace("/", "");
            str = str.Replace("-", "");
            str = str.Replace("|", "");
            str = str.Replace("?", "");
            str = str.Replace(">?", "");
            str = str.Replace("?<", "");
            str = str.Replace(" ", "");
            return str;
        }

posted @ 2012-07-18 12:37  美丽的矩阵  阅读(105)  评论(0编辑  收藏  举报