KeyValueListDeleteByKey

Searches a list of key value pairs for a specific key and, if it is exists in the list, removes the corresponding pair.

Syntax

KeyValueListDeleteByKey( 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 the CSV list with the pair containing the specified key removed; 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=River E. Wyles, 2=Eva Rosalene, 3=Vacant, 4=Vacant"

The hotel has recently undergone major refurbishment, during which the wall between rooms 3 and 4 was removed, creating a single, larger suite with the number 3. As a result, the room entry in the key value pair list will need to be removed using the following expression:

KeyValueListDeleteByKey( GuestListNow, "=", ",", "4" );

The expression locates the key representing room 4, then removes the entire pair "4=Vacant" from the list. The comma immediately before the pair is also removed, ensuring that the resulting list's syntax is valid, as shown below:

"1=River E. Wyles, 2=Eva Rosalene, 3=Vacant"