W_COUNT Function


Count as N = W_COUNT(C character[,C separator])



A character string


Optional. Default = space (" "). The character that separates words. If the optional Word_Delimiter parameter is not specified, a word is any sequence of one or more characters separated either by a space or the start or end of the string. Character


Counts number of words in a character string.


W_COUNT() returns an integer Count equal to the number of words in the specified character. You may often need to extract the last name from a field that contains both a first name and last name, or the zip code from a field that contains the city, state, and zip. This can be a difficult problem because, in the case of names, for example, some records can contain middle initials. In the case of addresses, some city names can be one word and others may be two words. Using W_COUNT() , you can count the number of words in a field. This makes it easy to extract the last word in a field. If separator is specified, then Alpha Anywhere, then Alpha Anywhere counts the strings that are delimited by the separator character.


w_count("Phineas T. Whopee") -> 3
w_count(CITYSTZIP) -> 3, if CITYSTZIP contains "Yorktown Heights, NY10598"

To extract the last name from a field that contains full names, use the following expression:

word(FULLNAME, w_count(FULLNAME))

An alternative to using W_COUNT() is to use the WORD() function with a negative parameter. The following expression also returns the last word in a field:

w_count("John Smith" + "," + "Alpha Software" + "," + "BurlingtonMA01803", ",") -> 3

See Also