You are here: Function Reference > Alphabetical Listing > P > ParseListItem

ParseListItem

Use this function to return indexed components from the formatted text.

Note Use the ParseListCount and ParseListItem functions when accepting tokenized (comma or semicolon-delimited) data, such as data from a spreadsheet program or other application. These are sometimes referred to as CSV (comma separated value) files.

Syntax

ParseListItem (String, Item, Separator)

Parameter

Description

String

Enter a formatted string to search and parse.

Item

Enter the number of the item you want from within that formatted string.

If you omit this parameter, the first item parsed from the formatted text is returned.

Separator

Enter a list of character separators used within the formatted text parameter.

If you omit this parameter, the semicolons and commas are used.

The return value is a string of text. If the formatted text contains leading or trailing spaces on items formatted within it, they are not removed. You can use the Trim function on the returned text if you do not want the spaces.

If the first parameter text starts with delimiter characters, they will be skipped. Because the function will return spaces, you know when you have exceeded the number of items formatted within the string when you get an empty string returned.

Note If you do not have at least a space character between delimiters, this will not be identified as a separate index item.

Example

Here are some examples. Assume xString = "A,B;C"

value = ParseListItem(xString)

The value is A.

value = ParseListItem(xString,3)

The value is C because the default separators include both commas and semicolons.

value = ParseListItem(xString,1,";")

The value is A,B. Note in this example the third parameter overrides and assigns only the semicolon as a valid separator. Therefore, the first item includes all text up to the first semicolon.

For these examples, assume xString = ";A;,B,;C"

value = ParseListItem(xString)

The value is A. Note that if the formatted string starts with separator characters they are skipped.

value = ParseListItem(xString,2)

The value is B. Note again how adjacent separators without intervening characters (or space) are skipped. Therefore the semicolon and comma ( ;,) between the A and B are treated as a single separation.

value = ParseListItem(xString,3)

The value is C. Note again how adjacent separators without intervening characters (or space) are skipped. Therefore the semicolon and comma (;,) between the A and B are treated as a single separation and the semicolon and comma (;,) between the B and C are also treated as a single separation.

value = ParseListItem(xString,3,",")

The value is ;C. Note the third parameter overrides and assigns only the comma as a valid separator. Therefore the third index item includes all text following the second comma to the end of the string (because no other separators were encountered).

For these examples, assume xString = "; ,A; ,B;"

value = ParseListItem(xString)

The value is a space. Note that there is at least one intervening character — a space — between the first set of separator characters.

value = ParseListItem(xString,2)

The value is A.

value = ParseListItem(xString,3)

The value is a space.

value = ParseListItem(xString,4)

The value is B.

value = ParseListItem(xString,5)

The value is an empty string because this index item exceeds the list of items provided.

See also