Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
LIKE()
This function compares a string to a template string that may contain wildcards.
lMatch = LIKE( cWildcardString, cCompareString )
Parameter |
Value |
Meaning |
cWildcardString |
Character |
The template string. It may contain the wildcards "*" (0 or more characters) and "?" (one character). |
cCompareString |
Character |
The string to check against the template. |
lMatch |
.T. |
cCompareString matches the form of cWildcardString. |
.F. |
cCompareString does not fit the form of cWildcardString. |
We’ve never actually used this function, so we asked around before writing this section and couldn’t find anyone who’d ever used this function. However, in playing with it, it turns out to be fairly neat.
Unlike the DOS wildcards, “*” and “?” may appear multiple times in cWildcardString, and the “*” isn’t restricted to the end of the string. So, for example, you could use “*X*” to check for a string containing at least one “X.” Note that these are not the same wildcards as the LIKE clause of SQL-SELECT, even though they do behave the same way.
One use we can imagine for LIKE()
is to check user input to see if it forms a valid name of the type needed for an operation. One trap here is that LIKE()
is case-sensitive, so you must remember to compare items in the same case or use UPPER()
.
For some reason, LIKE()
doesn’t use SET EXACT
to determine the significance of trailing blanks. Instead, it’s controlled by SET COMPATIBLE
. The Fox version (OFF or FOXPLUS) considers trailing blanks, while the dBASE version (ON or DB4) ignores them.
? LIKE("T*", "Tamar") && Returns .T.
? LIKE("T*", "Ted") && Returns .T.
? LIKE("T*", "Cherry Tomato") && Returns .F.
? LIKE("*.DBF", UPPER(cFileName)) && Is it a table name?
Difference(), LikeC(), Select-SQL, Set Compatible, Set Exact, Soundex()