RowFilter LIKE 操作

发布于 2024-08-30 10:38:59 字数 215 浏览 9 评论 0原文

我知道以下内容不允许作为行过滤器

“canada%.txt”或“canada*.txt”

,我想我可以重写我的过滤器以

file_name like 'Canada%' and file_name like '%.txt' 

使其工作。

但是有没有更简单的方法而不是确定 % 的位置并分割字符串呢?

I know that the following is not allowed as a row filter

'canada%.txt' or 'canada*.txt'

and I guess I can rewrite my filter as

file_name like 'Canada%' and file_name like '%.txt' 

should work.

But is there an easier way instead of determing where the % is and spliting the string?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七月上 2024-09-06 10:38:59

我不认为过滤器表达式中允许使用 CHARINDEX。

您可以尝试从 C# 动态构建过滤器字符串(未经测试,但这里有一个可能的语法):

//split the original string using the wildcard as the delimiter
string[] f = s.Split('%');

//use the resulting array to build the resultstring
string resultstring = 'file_name like "' + f[0] + '%" and file_name like "%' + f[1] + '"'

//view.RowFilter = resultstring;

I don't believe that CHARINDEX is allowed in the filter expression.

You might try to dynamically build the filter string from C# (very much untested, but here's a possible syntax):

//split the original string using the wildcard as the delimiter
string[] f = s.Split('%');

//use the resulting array to build the resultstring
string resultstring = 'file_name like "' + f[0] + '%" and file_name like "%' + f[1] + '"'

//view.RowFilter = resultstring;
最丧也最甜 2024-09-06 10:38:59

这是我想出的解决方案

    private string CreateRowFilter(string remoteFilePattern)
    {
        string[] pattern = remoteFilePattern.Split(new char[] { '*', '%' });
        int length = pattern.GetUpperBound(0);

        if (length == 0)
        {
            return String.Format("Name = '{0}'", pattern[0]);

        }

        StringBuilder fileter = new StringBuilder(
                 String.Format("Name LIKE '{0}*' ", pattern[0]));

        for (int segment = 1; segment < length; segment++)
        {
            fileter.Append(
                 String.Format("AND Name LIKE '*{0}*' ", pattern[segment]));
        }

        if(String.IsNullOrEmpty(pattern[length]) == false)
        {
            fileter.Append(
                 String.Format("AND Name LIKE '*{0}' ", pattern[length]));
        }

        return fileter.ToString();
    }

Here is the solution that I came up with

    private string CreateRowFilter(string remoteFilePattern)
    {
        string[] pattern = remoteFilePattern.Split(new char[] { '*', '%' });
        int length = pattern.GetUpperBound(0);

        if (length == 0)
        {
            return String.Format("Name = '{0}'", pattern[0]);

        }

        StringBuilder fileter = new StringBuilder(
                 String.Format("Name LIKE '{0}*' ", pattern[0]));

        for (int segment = 1; segment < length; segment++)
        {
            fileter.Append(
                 String.Format("AND Name LIKE '*{0}*' ", pattern[segment]));
        }

        if(String.IsNullOrEmpty(pattern[length]) == false)
        {
            fileter.Append(
                 String.Format("AND Name LIKE '*{0}' ", pattern[length]));
        }

        return fileter.ToString();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文