compare

Prev Next

Function Names

compare

Description

This function performs a comparing between 1st parameter (a value) and 2nd parameter containing a code piece or string containing the comparison expression.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

2

Parameters

No.TypeDescription
1
input
all types Value to compare

This value will be compared with the comparison expression in the 2nd function parameter.

2
code
comparison expression
:string
Comparison expression

This parameter is a piece of code typically found on the right-hand side of a comparison with '=' or '<>'. Single values, ranges (e.g. 3..5), multiple values separated by commas are supported. For text comparison, wildcards are supported if the string is of type softquoted string.

Return value

TypeDescription
boolean Comparison result

Examples

  a[] = 3; b[] = 5; c[] = 7;
  ex[] = ">6";

  echo("Greater than 4: ", compare( a[],  >4 ), " ", compare( b[],  >4 ), " ", compare( c[],  >4 ) );
  echo("Greater than 6: ", compare( a[],:ex[]), " ", compare( b[],:ex[]), " ", compare( c[],:ex[]) );

  // Note the required colon.  Otherwise ex[] is seen as variable to compare with.

Output

Greater than 4: false true true
Greater than 6: false false true
Try it yourself: Open LIB_Function_compare.b4p in B4P_Examples.zip. Decompress before use.

See also

calc