The LIKE operator returns TRUE if a string matches a given mask.
expr [NOT] LIKE mask [ ESCAPE "char" ]
The mask can be any combination of characters, including the % and _ wildcards:
The ESCAPE clause can be used to define an escape character different from the default backslash. It must be enclosed in single or double quotes.
A backslash (or the escape character specified by the ESCAPE clause) makes the operator treat the next character as a literal character, even if it is one of the special symbols in the mask list. This allows you to search for %,_ or \ characters.
Do not confuse with the LIKE clause of the DEFINE instruction .LIKE operators used in SQL statements are evaluated by the database server. This may have a different behavior than the LIKE operator of the language.
If you need to escape a wildcard character, keep in mind that a string constant must also escape the backslash character. As a result, if you want to pass a backslash to the LIKE operator (by using backslash as default escape character), you need to write four backslashes in the original string constant.
The next table shows some examples of string constants used in the source code and their equivalent LIKE pattern:
Original String Constant | Equivalent MATCHES pattern | Description |
---|---|---|
"%" | % | Matches any character in a non-empty string. |
"_" | _ | Matches a single character. |
"abc%" | abc% | Starts with abc. |
"*abc" | %abc | Ends with abc. |
"%abc%" | %abc% | Contains abc. |
"abc__" | abc__ | Strings equals abc followed by two additional characters. |
"\\%" | \% | Contains a single star character (the % wildcard is escaped) |
"%abc\\\\def%" | %abc\\def% | Contains abc followed by a backslash followed by def (the backslash is escaped) |
MAIN IF "abcdef" LIKE "a%e_" THEN DISPLAY "The value matches." END IF END MAIN