vb.net

Like operator in VB.Net not working as expected


Working in VB.Net:

? "0.326X0.450" Like "*#X#*#X#*#X#*"

Returns False, as expected

? "0.326X0.450" Like "*#X#*"

Returns True, as expected

? "0.326X0.450" Like "*#X#*#X#*"

Returns True, not what I expected. I assumed it would look for both Xs.

I am curious if there a Like operator that will distinguish "2.000X2.000" from "2.000X2.000X.2.000" where the 2.000 could be any arbitrary positive value?


Solution

  • I think the function CompilerServices.Operators.LikeString is what you're looking for. It works similarly to the Like operator but gives the expected result.

    CompilerServices.Operators.LikeString("0.326X0.450", "*#X#*#X#*#X#*", CompareMethod.Text) 'false
    CompilerServices.Operators.LikeString("0.326X0.450", "*#X#*", CompareMethod.Text) 'true
    CompilerServices.Operators.LikeString("0.326X0.450", "*#X#*#X#*", CompareMethod.Text) ' false