replace value(a, csv b, column c, default d, [encoding e, key column f, delimiter g])

This function searches for value a in the key column of a CSV file b. If the value is found, the function returns the value in column c, if the value is not found, d is returned.

Shouldn't the first column be used to search for a, parameter f allows to specify the column number to be used instead (starting with 1). If the CSV file's encoding is different from the system encoding, the charset can be specified with e.

The default field delimiter is a comma (,). Parameter g can optionally be used to define another field delimiter character. The first non-whitespace character within g is used. In order to define TAB or SPACE as a delimiter, please type \TAB resp. \SPACE into g.

Parameters


Parameter

Description

a

Value to be looked up in the file.

b

Name of CSV file.

c

Column to be used to replace a.

d

Default value to be used if a is not found.

e

(optional) File encoding. Default: System encoding or 8859_1 if none found.

f

(optional) Column to be used to search for a. Default: 1.

g

(optional) Optional CSV field delimiter. Default: ,


Examples


Assume the following CSV file ./conf/myCSVValues.csv


key1,key2,val1,val2,val3
key3,key4,val4,val5,val6

Parameter a

Parameter b

Parameter c

Parameter d

Parameter e

Parameter f

Result

key1

./conf/myCSValues.csv

5

No value found



val3

key2

./conf/myCSValues.csv

5

No value found



No value found

key2

./conf/myCSValues.csv

5

No value found


2

val3

xyz1

./conf/myCSValues.csv

5

ABC



ABC

key3

./conf/myCSValues.csv

3

No value found



val4

key4

./conf/myCSValues.csv

4

No value found


2

val5

key1

./conf/myCSValues.csv

12

ABC



Function terminates with an error.