From Xojo Documentation

Revision as of 19:06, 19 November 2009 by (talk) (Examples)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Returns the number of values (fields) in the string passed that are separated by the separator string passed. If the source string is binary data or you require case-sensitivity, use CountFieldsB instead.


result=CountFields(source, separator)

Part Type Description
result Integer The number of values in source that are separated by separator.
source String The original string.
separator String The character or characters that separate the values in source.


The CountFields function is useful for reading columns of data from a text file where the columns (fields) are delimited with a specific character or characters.

If the separator is not found within source, CountFields returns 1. If source is null, CountFields returns zero.


The example below returns 5.

Dim count as Integer
Dim s as String
count=CountFields(s, "*")

The following example returns three because it counts the null "field" after the (unnecessary) final field delimiter.

Dim count as Integer
Dim s as String
count=CountFields(s, "*")

See also the example that illustrates how to populate a PopupMenu control.

See Also

CountFieldsB, NthField, Split functions; TextInputStream object example.