set

Prev Next

Function Names

set

Description

This function converts a value provided to a set.

  • Numerals, Booleans, Dates: Put as single element into a set.
  • Sets: Will be passed through.
  • Strings: See below

In case of converting strings: The input string may be embedded in braces ("{ … }" ) or not. The elements must be separated with commas. The number of opening and closing braces must be equal. Braces inside quotation marks are considered as part of a text element to include.

  • If elements look like numerals and Booleans (e.g. 123, true) , then they will be converted accordingly
  • If elements look like unambiguous dates in the strict and exact format as listed below, then they will be converted to dates (optionally including time of day)
    • "YYYY-MM-DD": Dates
    • "hh:mm:ss": Times
    • "YYYY-MM-DD hh:mm:ss": Dates with times
    • "0000-00-00" Blank dates

Any additional or missing characters (incl. spaces) will suppress automatic date conversion. If you have other date formats (e.g. MM/DD/YY, hh:mm), convert them by dates afterwards with the date(…) function.

  • A blank value is assumed between 2 consecutive commas (e.g. {a,,b})
  • A blank value is also assumed if comma follows open brace or leads close brace symbols (e.g. {,a}, {a,})
  • 2 blank values are included in this sequence: {,}
  • One HTML entity will be decoded: ' ' single quotation mark / apostrophe

Reason: Strings in conversion from sets to string will be put into single quotation marks and internal single quotation marks needed to be encoded to avoid confusion with closing quotation marks

  • Nesting is supported, e.g. {a,{b,c}}
  • Symbols other than braces and commas are considered as strings, e.g. {+} -> '+' in 1st element.
  • No variable names (e.g. "{a[]}" , functions and expressions will be calculated. It's just plain data.



Note: This particular function does not support vectorization.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

1

Parameters

No.TypeDescription
1
input
valid types Value

Value to be converted as described above.

Return value

TypeDescription
set Result

Identified set

Examples

               echo( set ( "{a,1,{true,TRUE,false}} " ) );   // {{'a',1,{true,'TRUE',false}}}
               echo( set ( "a,1,{true,TRUE,false} " ) );     // {'a',1,{true,'TRUE',false}}
               echo( set ( "2019-07-14,10:30:00"  ) );       // 2 date values: { 2019-07-14,10:30:00 }
               echo( type( set ( "2019-07-14,10:30:00" ){0} ) );     // Check type of date
               echo( set ( "2019/07/14,10:30"  ) );          // 2 strings: { '2019/07/14','10:30' } (not qualified as dates)
               echo( set ( "{a,,b}"  ) );                    // 4 strings: { 'a','','','b' } (2 strings are blank)

Output

{{'a',1,{true,'TRUE',false}}}
{'a',1,{true,'TRUE',false}}
{'2019-07-14','10:30:00'}
date
{'2019/07/14','10:30'}
{'a','','b'}
Try it yourself: Open LIB_Function_set.b4p in B4P_Examples.zip. Decompress before use.