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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Function

Status
Not open for further replies.

creon

Technical User
Jul 28, 2004
5
0
0
US
Good morning all!

I am trying to count the number of instances of the number 2 in a long string of numbers but do not know the corrent syntax of the formula.

Ex: 4 6 1 2 9 0 4 1 2 2 5 4 <-- count the number of 2 in the string

Any ideas?

Creon
 
Hi creon,

Try this:
whileprintingrecords;
numbervar count2;
numbervar i;
stringvar mystring = '461290412254';

for i := 1 to len (mystring) do(
if mystring = '2' then
count2 := count2 + 1
);
count2

Hope it helps!
Dana
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top