MapKeyFind

Returns the value associated with a WIL map key.

Syntax:

MapKeyExist(map, key [,not_found])

Parameters:

(m) map: a variable containing a WIL map.

(s) key: a string to test for existents as a key in the passed in WIL map.

(i/s) not_found: [optional] a alternate value to return when the indicated key does not exist or the key's value is undefined in the specified map.

Returns:

(i/s)  if key exist in the map, the value associated with the key, or zero(0) or the value indicated by the not_found parameter when the key does not exit or the key's value is undefined.

 

The MapKeyFind function is used to obtain the value associated with the key in a WIL map. The function offers an optional "not found" value that the function returns when a key is not present in the targeted WIL map or the value associated with an existing key is undefined.. The optional not found value is useful when a map has actual values with the default not found value of zero associated  with one or more keys. The function is similar to calling the MapKeyExist function followed by using the key name in square brackets (map[key]) to access the value.  The advantage of using this function is that it can perform the same task in a single step instead of two which provides a modest performance boost over the two-step method.

Example:
  mCodes = MapCreate($"CA, Canada
  CN,China
  FI,Finiland
  DE,Germany
  JP,Japan
  LU,Luxembourg
  NO,Norway
  GB,United Kingdom of Great Britain and Northern Ireland
  US,United States of America
  $", '',@lf)
  
  ; Get the name associated with a country code
  sCc = 'DE'
  sCountry = MapKeyFind(mCodes, sCc , '<Unknown>')
  Message('Country Code Check', 'The country code: "':sCc:'" stands for the country "':sCountry:'"')
See Also:

MapCreate, MapFileGetCsv, MapFilePutCsv, MapKeyRemove, MapKeysGet, MapKeyExist