CSVListItemExists

Searches a CSV list for a specific set of values. The function returns True if at least one row contains the specified values, and False otherwise.

Syntax

CSVListItemExists( CSVList, KeywordList, ListSeparator, RowSeparator );

Parameters

Parameter Name Type Description Optional? Default Value
CSVList String The CSV list to inspect. No n/a
KeywordList String A CSV list of values to search for in CSVList. No n/a
ListSeparator String The single character that separates values in CSVList. Yes ,
RowSeparator String The single character that separates rows in CSVList. Yes |

Output

If at least one row in the CSV matches the specified data, the function will return True; otherwise, it will return False.

Use Case

An online clothes store provides a facility that lets customers add items to a virtual shopping basket. Each customer has their own basket, which will be emptied whenever they end their current session. Because the data is local and temporary, it is stored as CSV using the keyword UserBasket.

Each row of the basket CSV lists the customer's unique ID together with the chosen product's reference number, description and price, and the desired quantity, size and colour. An sample customer basket containing two rows is shown below:

"HV13796,P0001,Floral Dress,S,Blue,35.00,1|HV13796,P0002,Jeans,M,Maroon,45.00,2"

The site admin wants to prevent duplicate items being added to shopping baskets; there should only ever be one row in a CSV for each unique product in the customer's basket. When a customer attempts to add more items of a type already in their basket, the existing row for that item should be updated to include the additional quantity requested.

The mechanism for detecting whether an item already exists in a customer's shopping basket is written using CSVListItemExists, as shown below:

CSVListItemExists( UserBasket, NewBasketItem );

NewBasketItem is the same comma-separated list of values used to add new rows to the UserBasket CSV. The expression returns a value of True or False depending on whether or not the values entered already exist, and this can be used to determine whether a new row should be created, or the existing one updated.