2.5 Operators

Idoc Script supports several operators. This section describes the following:

2.5.1 Comparison Operators

Use the following comparison operators compare the value of two operands and return a true or false value based on the result of the comparison. These operators can be used to compare integers and Boolean values in Idoc Script.

If you are using Idoc Script in an HCSP or HCSF page, you must use special comparison operators. For more information, see the Oracle Fusion Middleware Developer's Guide for Content Server.

Operator Description Example
== equality <$if 2 == 3$> evaluates to false
!= inequality <$if 2 != 3$> evaluates to true
< less than <$if 2 < 2$> evaluates to false
<= less than or equal <$if 2 <= 2$> evaluates to true
> greater than <$if 3 > 2$> evaluates to true
>= greater than or equal <$if 3 >= 2$> evaluates to true

These are numeric operators that are useful with strings only in special cases where the string data has some valid numeric meaning, such as dates (which convert to milliseconds when used with the standard comparison operators).

  • For string concatenation, string inclusion, and simple string comparison, use the Special String Operators.

  • To perform advanced string operations, use strEquals, strReplace, or other string-related global functions.

2.5.2 Special String Operators

Use the following special string operators to concatenate and compare strings:

Operator Description Example
& The string join operator performs string concatenation. Use this operator to create script that produces Idoc Script for a resource include.
<$"<$include " & VariableInclude & "$>"$>
evaluates to:
<$include VariableName$>
like The string comparison operator compares two strings.
  • The first string is compared against the pattern of the second string. (The second string can use asterisk and question mark characters as Wildcards.)

  • This operator is not case sensitive.

  • Evaluates to FALSE:
    <$if "cart" like "car"$>
    
  • Evaluates to TRUE:

    <$if "cart" like "car?"$>
    
  • Evaluates to TRUE:

    <$if "carton" like "car*"$>
    
  • Evaluates to TRUE:

    <$if "Carton" like "car*"$>
    
| The string inclusion operator separates multiple options, performing a logical OR function. Evaluates to TRUE:
<$if "car" like "car|truck|van"$>

For example, to determine whether the variable a has the prefix car or contains the substring truck, this expression could be used:

<$if a like "car*|*truck*"$>

Important:

To perform advanced string operations, use strEquals, strReplace, or other string-related global functions. See "Strings" for a list.

2.5.2.1 Wildcards

The like operator recognizes the following wildcard symbols:

Wildcard Description Example
* Matches 0 or more characters.
  • grow* matches grow, grows, growth, and growing
  • *car matches car, scar, and motorcar

  • s*o matches so, solo, and soprano

? Matches exactly one character.
  • grow? matches grows and growl but not growth
  • grow?? matches growth but not grows or growing

  • b?d matches bad, bed, bid, and bud


2.5.3 Numeric Operators

Use the following numeric operators to perform arithmetic operations. These operators are for use on integers evaluating to integers or on floats evaluating to floats:

Operator Description Example
+ Addition operator.
<$a=(b+2)$>
- Subtraction operator.
<$a=(b-2)$>
* Multiplication operator.
<$a=(b*2)$>
/ Division operator.
<$a=(b/2)$>
% Modulus operator. Provides the remainder of two values divided into each other.
<$a=(b%2)$>

2.5.4 Boolean Operators

Use the following Boolean operators to perform logical evaluations:

Operator Description Example
and
  • If both operands have nonzero values or are true, the result is 1.
  • If either operand equals 0 or is false, the result is 0.

<$if 3>2 and 4>3$>
evaluates to 1
or
  • If either operand has a nonzero value or is true, the result is 1.
  • If both operands equal 0 or are false, the result is 0.

<$if 3>2 or 3>4$>
evaluates to 1
not
  • If the operand equals 0 or is false, the result is 1.
  • If the operand has a nonzero value or is true, the result is 0.

<$if not 3=4$>
evaluates to 1

Boolean operators evaluate from left to right. If the value of the first operand is sufficient to determine the result of the operation, the second operand is not evaluated.