当前位置:Gxlcms > asp.net > 使用DataTable.Select 方法时,特殊字符的转义方法分享

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

时间:2021-07-01 10:21:17 帮助过:19人阅读

代码如下:
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;
        }

人气教程排行