PARSECOUNT function   

Purpose

Return the count of delimited strings in a string expression.

Syntax

x& = PARSECOUNT(string_expr [, {[ANY] string_delimiter | BINARY}])

Remarks

PARSECOUNT uses the same rules as PARSE$ in the determination of fields within string_expr.  Individual fields within string_expr are evaluated, and the tally of the fields forms the result value.

It is important to note that PARSECOUNT may only be used with string data which contains variable length sub-fields, each of which is separated by a delimiter.  To determine the count of fixed length data, divide the StringExpr length by the sub-field length.  If this function is used with fixed length data, the results are undefined.

string_expr

This is the string to examine and parse.  If StringExpr is empty (a null string) or contains no delimiter character(s), the string is considered to contain exactly one sub-field.  In this case, PARSECOUNT returns the value 1.

string_delimiter

This defines one or more characters to use as a delimiter.  To be valid, the entire delimiter must match exactly, but the delimiter itself is never returned as part of the field.

If string_delimiter is not specified, or contains an empty string, special rules apply.  The delimiter is assumed to be a comma.  Fields may optionally be enclosed in quotes, and are ignored before the result string is returned.  Any characters that appear between a quote mark and the next comma delimiter character are discarded.  If no leading quote is found, any leading or trailing quotes are trimmed before the result string is returned.

ANY

If the ANY keyword is used, string_delimiter contains a set of characters, any of which may act as a delimiter character.  If the ANY keyword is omitted, the entire string_delimiter string acts as a single delimiter.

BINARY

The BINARY option returns the number of sub-fields and presumes that StringExpr was created with the JOIN$/BINARY function, or its equivalent, which creates a string in the PowerBASIC and/or Visual Basic packed string format:  If a string is shorter than 65535 bytes, it starts with a 2-byte length WORD followed by the string data. Otherwise it will start with a 2-byte value of 65535, followed by a DWORD indicating the string length, then the actual string data.

See also

JOIN$, PARSE, PARSE$

Example

a& = PARSECOUNT("one,two,three")   ' returns 3

a& = PARSECOUNT("one;two,three")   ' returns 2

a& = PARSECOUNT("")                ' returns 1

a& = PARSECOUNT("xx1x","x")        ' returns 4

a& = PARSECOUNT("1;2,3", ANY ",;") ' returns 3