使用 DataTable.Select 方法时 ,特殊字符的转义方法

 public static string Replace(string oldStr)
        {
            if (string.IsNullOrEmpty(oldStr))
            {
                return "";
            }
            string str2 = Regex.Replace(oldStr, @"[\[\+\\\|\(\)\^\*\""\]'%~#-&]", delegate(Match match)
            {
                if (match.Value == "'")
                {
                    return "''";
                }
                else
                {
                    return "[" + match.Value + "]";
                }
            });
            return str2;
        }

常见的特殊字符 基本都能转义 ,布吉岛 还有没有漏掉的 ,目前使用正常 。

posted @ 2013-10-18 10:46  多夢的歲月  阅读(4194)  评论(0编辑  收藏  举报