like operator

In a logical expression, you can compare a text expression against another string (called a like criterion), character position by character position from left to right. Use of this feature is similar to use of the SQL keyword like in SQL queries.

An example is as follows:

  // variable myVar01 is the string expression 
  // whose contents will be compared to a like criterion
  myVar01 = "abcdef";

  // the next logical expression evaluates to "true" 
  if (myVar01 like "a_c%")
    ;
  end

The like criterion can be either a literal or item of type CHAR or MBCHAR; or an item of type UNICODE. You can include any of these characters in the like criterion:

%

Acts as a wild card, matching zero or more of any characters in the string expression

_ (underscore)

Acts as a wild card, matching a single character in the string expression

\

Indicates that the next character is to be compared to a single character in the string expression. The backward virgule (\) is called an escape character because it causes an escape from the usual processing; the escape character is not compared to any character in the string expression.

The escape character usually precedes a percent sign (%), an underscore (_), or another backward virgule.

When you use the backward virgule as an escape character (as is the default behavior), a problem arises because EGL uses the same escape character to allow inclusion of a quote mark in any text expression. In the context of a like criterion, specify two backward virgules because the text available at run time is the text that lacks the initial virgule.

It is recommended that you avoid this problem. Specify another character as the escape character by using the escape clause, as shown in a later example. However, you cannot use a double quote mark (") as an escape character.

Any other character in likeCriterion is a literal that is compared to a single character in string expression.

The following example shows use of an escape clause:

  // variable myVar01 is the string expression 
  // whose contents will be compared to a like criterion
  myVar01 = "ab%def";

  // the next logical expression evaluates to "true" 
  if (myVar01 like "ab\\%def")
    ;
  end

  // the next logical expression evaluates to "true"
  if (myVar01 like "ab+%def" escape "+")
    ;
  end

Related reference
EGL statements
Logical expressions
Text expressions