Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count # of times a word appears in a field

Status
Not open for further replies.

dacards

Technical User
Apr 11, 2006
26
US
I'm pulling a field into crystal that's a free form diary(work log) for users. Need to count the # of times a word appears in that field. When I run the report I could receive back any number of records, and within each record "the word" appears at least once but could be more.

For example:

Tkt # Work Log
123 California
124 Connecting flight from New York to California.
215 Leaving from Florida.
304 Flights from California to New York or from Florida to California.
405 Flights from New York to Florida.

I need a count to pull back the number of times the word "California" appears in the work logs. In the example above it should come back to a total of 4.
 
Try a formula like this:

whileprintingrecords;
stringvar array x := split({table.worklog}," ");
numbervar i;
numbervar j := ubound(x);
numbervar n;

for i := 1 to j do(
if x = {?parm} then
n := n + 1);
n

If you have a group you want to count within, then create a reset variable for the group header:

whileprintingrecords;
numbervar n := 0;

-LB
 
Had to tweak it a bit but this helped a ton. As always thanks for the quick reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top