subset ...

Prev Next

Function Names

subset, subset ignore case, subset ignore blanks, subset ignore both, subset recursive, subset recursive ignore case, subset recursive ignore blanks, subset recursive ignore both

Description

This function checks whether the parameter set in the 2nd function parameter is a subset of the 1st parameter set.
The recursive will also include the nested parameter sets into subset checking, e.g. subset( {{a,b,c},c,d}, {{a,b},d} ) is true. Otherwise, {a,b,c} and {a,b} ares treated as different elements. Counts the number of elements which match with the supplied value.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

2

Parameters

No.TypeDescription
1
input
parameter set or string input parameter set

If provided as a parameter set: Will be used for counting elements
If provided as a quoted string: The string will be converted to a parameter set containing one element.
If provided as a unquoted or softquoted string: The comma-separated substrings will be converted to parameter set elements. '' is equivalent to {}.

2
input
valid types subset to check

If provided as a parameter set: Will be used for counting elements
If provided as a quoted string: The string will be converted to a parameter set containing one element.
If provided as a unquoted or softquoted string: The comma-separated substrings will be converted to parameter set elements. '' is equivalent to {}.
Attention: In contrast to other parameter set functions, wildcards are not supported here.

Return value

TypeDescription
boolean 2nd parameter set is a subset of 1st parameter set

Number of elements (nested elements are not counted)

Examples

      a[] = { a, b, c, {d, e}, f, {} };
      echo ( subset( a[], {} ) ); // True (Empty set is always subset)
      print( subset ( a[], {A} ), ", " ); // False (A is not in the set)
      echo ( subset ignore case( a[], {B,A} ) ); // True (cases ignored)

      print( subset( a[], {c,{},f} ), ", " ); // True (Empty set is always subset)
      print( subset( a[], {f,{d,e}} ), ", " ); // True (Empty set is always subset)
      print( subset( a[], {f,{e,d}} ), ", " ); // False. {e,d} not equal to {d,e}
      echo ( subset recursive( a[], {{d,e}} ) ); // True. {e,d} not equal to {d,e}

Output

true
false, true
true, true, false, true
Try it yourself: Open LIB_Function_subset.b4p in B4P_Examples.zip. Decompress before use.