BEGINS - returns TRUE if one string begins with another string.
string1 BEGINS string2
If string1 BEGINS with (or is equal to) string2 this will return true. Otherwise it will return false. If string two is empty ("") it will always return true.
BEGINS is very useful in queries where you want to search the beginning of something, for instance a name. But it's basically a function working on strings.
DEFINE VARIABLE str AS CHARACTER NO-UNDO.
DEFINE VARIABLE beg AS CHARACTER NO-UNDO.
str = "HELLO".
beg = "HELLO".
DISPLAY str BEGINS beg. // yes
str = "HELLO".
beg = "H".
DISPLAY str BEGINS beg. // yes
str = "HELLO".
beg = "".
DISPLAY str BEGINS beg. // yes
str = "HELLO".
beg = "HELLO WORLD".
DISPLAY str BEGINS beg. // no
MATCHES returns true if certain wildcard critera is met in a string.
string1 MATCHES expression
Returns true if string1 matches the wildcard expression:
* (asterisk) = 0 to n characters (basically any string of any length)
. (period) = wildcard for any character (except null)
DEFINE VARIABLE str AS CHARACTER NO-UNDO.
DEFINE VARIABLE beg AS CHARACTER NO-UNDO.
str = "HELLO".
beg = "HELLO".
DISPLAY str MATCHES beg. // yes
str = "HELLO".
beg = "H*".
DISPLAY str MATCHES beg. // yes
str = "HELLO".
beg = "*O".
DISPLAY str MATCHES beg. // yes
str = "HELLO WORLD".
beg = "HELLO.WORLD".
DISPLAY str MATCHES beg. // yes
str = "HELLO WORLD".
beg = "*WORL..".
DISPLAY str MATCHES beg. // no
str = "*HELLO WORLD".
beg = "WOR*LD".
DISPLAY str MATCHES beg. // no