Token_Count()

<< Click to Display Table of Contents >>

Navigation:  Available Functions >

Token_Count()

Syntax

Token_Count( <CharacterField>, <Delimiter> )

 

Purpose

To count the number of words in a character field.

 

Parameters

<CharacterField> is the name of any character field in DonorQuest, such as the last or first name field.

 

<Delimiter> is usually a quoted space (" "). In general, <Delimiter> is whatever separates words within the field in which you wish to count the number of words. In most cases, words within fields are separated by a space, but you may also have fields in which commas or semicolons are used to separate words or groups of words.

 

Returns

The number of words in <CharacterField>.

 

Usage

Token_Count() can be used very simply to count the number of words in a character field. Word counts can be useful if you wish to design a selection that identifies all the donors who have a certain number of words in a particular field. As with the other "token" functions, the power of Token_Count() goes well beyond simply dealing with words within fields. The term "token" really applies to any part of a character field that is delimited by a special character or characters. It could, for example, count the number of semicolon-delimited character groupings in a field.

 

Example

Being able to determine the number of words in a field can be quite useful. For example, the donor type field is normally used to designate the type of a donor -- usually individual or organization. However, after importing data from another program which does not have a donor type field, you would normally have to do manual data entry on each imported record to properly set the donor type field.

 

Alternatively, you could use Token_Count() to identify the imported records which have more than one word in the last name field -- they have a very high probability of being organizations. For those donors, you could then do an automatic replacement of the donor type field with "O" for organization. Similarly, you could identify the imported record with a single word in the last name field, and do an automatic replacement of the donor type field with "I" for individual.

 

The following example shows how to use Token_Count() to count the number of words in the last name field:

 

CALL

RESULT

.Last_Name.

Intrepid Systems

Token_Count( .Last_Name., " " )

2