MapLookupΒΆ

MapLookup uses a hashing algorithm to quickly find the map element with a key that exactly matches the given key.

data = MapLookup(hMap, ssKey)
data = MapLookup(hMap, ssKey, default_value)

Return Value

data is a real, complex or string matrix. In case of an error the function returns 0.

Parameters

hMap

hMap Identifies the map.

ssKey

ssKey specifies the key that identifies the element to be looked up.

default_value

The function returns the value default_value, if the key ssKey does not exist in the map . default_value can be a real, complex or string matrix.

Comment

To check if the return value is valid the ObjGetOk can be used. If the key does not exist in the map ObjGetOk returns FALSE (0).

Example

hMap = MapCreate();
MapSetAt(hMap, "Test1", [1,2,3,4,5,6]);
MapSetAt(hMap, "Test2", [2,5,7,6,3,1,6,7,8]);
MapSetAt(hMap, "Header1", ["1,5l", "4 Valves"]);
if (MapKeyExists(hMap, "Test2") {
    rmStr = MapLookup(hMap, "Test2");
} else
    // set to default:
    rmStr = [2,5,7,6,3,1,6,7,8];
}
// or
rmStr = MapLookup(hMap, "Test1", [2,5,7,6,3,1,6,7,8])

History

Version Description
5.7.0 New parameter default_value added.
4.2.0 The function can return 8-bit clean strings (may contain 0-characters).

id-2108427