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 occurance of word in a string

Status
Not open for further replies.

DBAFrog

Programmer
Sep 26, 2002
61
US
Some of the criteria I have to count is in a string. I.E.:
'RECIEVING STOLEN PROP. 25-50 (AUTO PARTS)' and I need to count based on the word = AUTO
I tried INSTR to do a boolean

NumberVar Count1;
If instr({Query.CHARGES_DESC},"AUTO") > 1
then Count1 := Count1 +1

but this didn't work, then I tried STRCMP

NumberVar Count1;
If strcmp({Query.CHARGES_DESC},"AUTO") => 4
then Count1 := Count1 +1

and it didn't work.
I am probably focusing on the right idea with the wrong syntax...any suggestions?

TIA...DBAFrog
 
This:

"NumberVar Count1;
If instr({Query.CHARGES_DESC},"AUTO") > 1
then Count1 := Count1 +1"

Should be:

NumberVar Count1;
If instr({Query.CHARGES_DESC},"AUTO") > 0
then Count1 := Count1 +1

A simpler means is to create a Running Total, counting any field, and in the evaluate use a formula, place:

instr({Query.CHARGES_DESC},"AUTO") > 0

-k kai@informeddatadecisions.com
 
Do you need to count the occurrences of a word in a string, as your post indicated, or just test to see if the string exists?

SVs formula should wokr great to test if it exists in the string, but you maigh have, for instance the string "AUTO AUTOMOBILE AUTOMATON AUTOMATIC" which contains "AUTO" 4 times. Would you want this string to return a count of 4?
Software Training and Support for Macola, Crystal Reports and Goldmine
251-621-8972
dgilsdorf@mchsi.com
 
dgillz,
you have a great point.
But, for my purposes I know that each string only contains the word AUTO once.

thanks,

frog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top