ArrayToDictionary
(System Library)
Description: | Returns a dictionary if given an array of key names and a matching array of values. |
Returns: | Dictionary |
Usage: ![]() |
Script Only. |
Function Groups: | Array, Dictionary |
Related to: | Dictionary |
Format: ![]() |
System.ArrayToDictionary(KeyArray, Values[, CaseSensitive]) |
Parameters: |
KeyArray |
A one-dimensional array of key names for the dictionary. |
Values |
A single value or a one-dimensional array of values matching the names in KeyArray. |
CaseInsensitive |
Optional Boolean. Set TRUE for a case sensitive dictionary. Defaults to TRUE. |
Comments: |
This module is a member of the System Library, and must therefore be prefaced by \System. as shown in the "Format" section. If your application predates version 11.2, use the backslash notation rather than dot: \System\ Beware of the following edge cases:
For example, with the default setting (CaseInsensitive==FALSE), ArrayToDictionary(MakeArray("A", "a"), MakeArray(1, 2)) gives Dictionary(“A”:2). The later value overwrites the earlier value.
For example, ArrayToDictionary(MakeArray("A", "a", “”), MakeArray(1, 2, 3)) returns a numeric value 3. A len(0) string is taken as Invalid, and is not allowed as key. As a result, the returned address is the dictionary itself instead of the dictionary[key], and the value is then stored in the dictionary itself. The Value that should be assigned to dictionary[key] is then assigned to the dictionary itself (in our example, it’s 3). Dict[""] has the same behavior as RootValue(Dict). ArrayToDictionary should detect a "" key and either fail entirely or leave out that item, and the behavior should be documented. |
Examples:
D = System.ArrayToDictionary(MakeArray("a", "b"), TRUE)
is the same as
D = Dictionary(); D["a"] = TRUE; D["b"] = TRUE;
D = ArrayToDictionary(MakeArray("a", "b"), MakeArray(Invalid, 123))
is the same as
D = Dictionary() D["a"] = Invalid; D["b"] = 123;