Returns the number of items in a CSV line.
ItemCountCsv (line, flags [, delimiter])
(s) line specifies a CSV line (see below).
(i) flags can be set to 0, or can specify one or more of the following values combined with the bitwise OR ('|') operator:
Value Meaning
1 treat leading and trailing whitespace as significant
(s) delimiter (optional) specifies the character used to separate values in the line. It can be any single character except a space, null, carriage return, line feed or quotation mark (double quote). If omitted, a comma will be used as the delimiter.
(i) the number of items in the CSV line.
This function is like ItemCount, but instead of a list, it counts items in a CSV line. A CSV ("comma separated values") line consists of comma-delimited items. Items may optionally be enclosed in quotation marks (aka, "double quotes").
There are two cases where an item *must* be enclosed in quotation marks:
(1) If the item contains a comma
(2) If the item contains a quotation mark
Here are some examples:
1,2,3,4,5
"January","February","March"
"Doe, John",20
In order to embed a quotation mark in an item, you must replace it with two quotation marks (i.e., add an extra quotation mark). For example, you would specify the item "My Fair Lady" (with quotes) as:
"""My Fair Lady"""
Each quotation mark is doubled, and the entire item is enclosed in a set of quotation marks.
Normally, whitespace outside of quoted strings is ignored. The following two lines would be considered identical:
A,B,C
A, B, C
But if you specify a "flags" value of 1, then the whitespace will be considered part of the items. Whitespace *inside* a quoted string is always preserved, regardless of the "flags" value:
" This line has spaces around it "
Similarly, whitespace outside of a quoted string is always ignored. i.e., the following two lines are considered identical, regardless of the "flags" value
"String 1","String 2","String 3"
"String 1", "String 2", "String 3"
line = '"January","February","March"' n = ItemCountCSV(line, 0, ",") Message("Note", "There are %n% items in this CSV line")
ItemCount, ItemExtract, ItemExtractCsv, ItemInsert, ItemLocate, ItemLocateWild, ItemRemove, ItemReplace, ItemSort, Lists Explained