LIKE

result = String LIKE Pattern

The pattern matching operator.


StringThe string you want to test (String).
PatternThe string pattern to match:
? - matches any single character
* - matches zero or more characters
# - matches any single digit (0-9)
[charlist] - matches any single character in charlist
[!charlist] - matches any single character not in charlist.

REMARKS
* This is an operator.
* For more information, refer to the Strings & Characters > LIKE Operator page.
* This operator supports wildcards (? and *).
* To match special characters [ ] ? * # place them inside square brackets.
* This operator will make a case insensitive comparison.
* This operator is equal in precedence to all the comparison operators.
* The type of string comparison used depends on the Option Compare statement.
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print "some text" Like "*"    '= True  
Debug.Print "ab__cd" Like "ab*cd" '= True
Debug.Print "ab-cd" Like "ab?cd" '= True
Debug.Print "ab1cd" Like "ab?cd" '= True
Debug.Print "ab1cd" Like "ab#cd" '= True
Debug.Print "---ab" Like " ""*ab" '= False
Debug.Print "123ab" Like "###ab" '= True
Debug.Print "123ab" Like "???ab" '= True
Debug.Print "123" Like "*" '= True
Debug.Print "abc" Like "###" '= False
Debug.Print "1" Like "[123]" '= True
Debug.Print "2" Like "[!123]" '= False

Debug.Print "a*c" Like "a[*]c" '= True
Debug.Print "a?c" Like "a[?]c" '= True
Debug.Print "abc" Like "a[*]c" '= False
Debug.Print "abc" Like "a[?]c" '= False
Debug.Print "abc" Like "a*c" '= True
Debug.Print "abc" Like "a?c" '= True

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top