KeyValueListGetByKey
Searches a list of key value pairs for a single key to find its matching value.
Syntax
KeyValueListGetByKey( KeyValuePairList, KeyValueConnector, KeyValuePairSeparator, Key );
Parameters
Parameter Name | Type | Description | Optional? | Default Value |
---|---|---|---|---|
KeyValuePairList | String | A list containing one or more key value pairs. | No | n/a |
KeyValueConnector | String |
The single character used in the list to map each key to its respective value. |
No | n/a |
KeyValuePairSeparator | String | The single character that separates key value pairs in the list. | No | n/a |
Key | String |
The key whose value to search for. |
No | n/a |
Output
If the key exists, the function will return its matching value; otherwise, it will return False.
Use Case
A hotel booking system exports nightly data listing the occupants of each of their rooms. This data is arranged as a list of key value pairs, where they key represents a room number and the corresponding value gives the name of the person staying in that room. Each key is mapped to its value by an equality sign (=) and the pairs are separated using a comma.
A small sample of this data - the entirety of which is referred to with the keyword GuestListNow - is as follows:
"1=Bill S. Preston, 2=Ted Theodore Logan, 3=Chuck De Nomolos, 4=Jim Martin"
To quickly find the name of the person staying in a particular room, the booking manager implements the following expression:
KeyValueListGetByKey( GuestListNow, "=", ",", ChosenRoom );
The value assigned to the ChosenRoom keyword will determine which of the guest names will be returned by the expression above. For example, if ChosenRoom was given a value of 3, the value returned by the expression will be "Chuck De Nomolos".