Like Operator

Syntax

str1 Like str2

Group

Operator

Description

Returns the True if str1 matches pattern str2. The pattern in str2 is one or more of the special character sequences shown in the following table:

Parameters

Chars Description
? Matches any single character.
* Matches zero or more characters.
# Matches a single digit (0-9).
[charlist] Matches any character in the list.
[!charlist] Matches any character not in the list.

Example


Sub Main
    Debug.Print "abcdfgcdefg" Like "" ' False
    Debug.Print "abcdfgcdefg" Like "a*g" ' True
    Debug.Print "abcdfgcdefg" Like "a*cde*g" ' True
    Debug.Print "abcdfgcdefg" Like "a*cd*cd*g" ' True
    Debug.Print "abcdfgcdefg" Like "a*cd*cd*g" ' True
    Debug.Print "00aa" Like "####" ' False
    Debug.Print "00aa" Like "????" ' True
    Debug.Print "00aa" Like "##??" ' True
    Debug.Print "00aa" Like "*##*" ' True
    Debug.Print "hk" Like "hk*" ' True
End Sub