KeyValueListUpdateValueByKey

Searches a list of key value pairs for a specific key. If that key exists, the function replaces the existing value mapped to that key and returns the updated list in full.

Syntax

KeyValueListUpdateValueByKey( KeyValuePairList, KeyValueConnector, KeyValuePairSeparator, Key, Value );

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
Value String The value to map to the specified Key. No n/a

Output

If the key exists, the function will return the CSV list with the new value applied to the specified key; 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=Marty McFly, 2=Emmett Brown, 3=Biff Tannen, 4=Gerald Strickland"

After Biff Tannen ends his stay at the hotel, a new guest named Marvin Berry takes his place in room 3. The manager uses the following expression to update the guest list:

GuestListNow:= KeyValueListUpdateValueByKey( GuestListNow, "=", ",", "3", "Marvin Berry" );

The expression locates the key representing room 3, then changes the associated value to "Marvin Berry". The updated section of the list assigned back to GuestListNow is as follows:

"1=Marty McFly,2=Emmett Brown,3=Marvin Berry,4=Gerald Strickland"