在VB.NET“喜欢”运营商可能的错误? [英] Possible bug in VB.NET 'Like' operator?

查看:150
本文介绍了在VB.NET“喜欢”运营商可能的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么是它下面的计算结果为

Why is it that the following evaluates as True?

Dim result = "b" Like "*a*b"

感谢。

编辑:
对此归纳了一下,下面的返回


To generalize this a bit, the following returns True:

"String1" Like "*AnyText1*AnyText2*AnyText???******????*String1"

VBA工作正常,返回
PowerShell的正常工作,返回

VBA works correctly, returning False.
PowerShell works correctly, returning False:

PS C:\Users\XXX> "b" -Like "*a*b"
False

EDIT2:
链接到错误报告:
https://connect.microsoft.com/VisualStudio/feedback/details/748415/a-bug-in-net-like-operator


The link to the bug report:
https://connect.microsoft.com/VisualStudio/feedback/details/748415/a-bug-in-net-like-operator

推荐答案

我决定,为了好玩,开拓ilspy调试这个: - )

I decided, for fun, to open up ilspy to debug this :-)

在此方法;

    private static void MatchAsterisk(string Source, int SourceLength, int SourceIndex, LigatureInfo[] SourceLigatureInfo, string Pattern, int PatternLength, int PatternIndex, LigatureInfo[] PattternLigatureInfo, ref bool Mismatch, ref bool PatternError, CompareInfo Comparer, CompareOptions Options)

这个条件

                if (SourceLength <= 0)
                {
                    return;
                }

通过将其更改为

by changing it to

                if (SourceLength < 0)
                {
                    return;
                }

这似乎是使工作打算

it seem to be make it work as intended

我只是做了一些小的考验,没有什么大的

I only did a few small test, nothing big

这个问题是;它只是看最后​​一个星号,当它是有效的,被停在那里

the issue is; it is only looking at the LAST asterisk and when it was valid, was stopping right there

我小的变化之前,请确保它检查实际上是previous之一,或任何

my small change make sure to check the previous one, or anything in fact before it

我的修正

 Dim result = "b" Like "*a*b"
 now return false

 "String1" Like "*AnyText1*AnyText2*AnyText???******????*String1"
 now return false

但并返回true时,它需要返回true

but does return true when it need to return true

这篇关于在VB.NET“喜欢”运营商可能的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆