PARSECOUNT function   

Purpose

Return the count of delimited (sub) fields 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.

string_expr

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

string_delimiter

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.

If string_expr is empty (a null string), PARSECOUNT will return 1, indicating that one empty (null) field exists.  Similarly, if string_expr does not contain any delimiters, string_expr is considered to contain one field.

BINARY

The BINARY option returns the number of sub-fields and presumes that string_expr was created with the JOIN$/BINARY function, or its equivalent, which creates a string as a binary image or 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 a 2-byte value of 65535, followed by a DWORD indicating the string length, then finally the string data itself.

See also

JOIN$, PARSE, PARSE$, PATHNAME$, PATHSCAN$

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