string.countFields

Syntax string.countFields (string, delimiter)

Params string is the string in which you wish to determine the number of fields.

delimiter is the character that separates fields within the string.

Action Counts the number of fields in string, with a field being defined as a string of characters separated by a single delimiter character.

Returns Number indicating how many fields are in string.

Examples string.countFields ("Run-of-the-mill", '-')

   » 4

string.countFields ("Frontier scripters have more fun.", ' ')

   » 13

In this example, extra spaces after "have" count; they delimit empty fields.

string.countFields (".html", '.')

   » 2

When a delimiter is the first character in a string, the field preceding it is empty.

string.countFields ("index.", '.')

   » 1

When a delimiter is the last character in a string, the field following it is not counted.

Notes Every string has at least one field, even if it is empty.

If the last field is empty, it will not be counted.

Using this verb with a space as the delimiter may not produce the same results as string.countWords, since the two verbs will treat consecutive spaces and empty strings differently.

See Also string.nthField

string.countWords

Discuss