Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Counting number of instances in a string Post Reply Post New Topic
Author Message
Mailman
Newbie
Newbie
Avatar

Joined: 21 Apr 2008
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote Mailman Replybullet Topic: Counting number of instances in a string
     Posted: 08 Oct 2008 at 4:05am

Hi I have a string field called "database.weeks" which consists of a string made up of Y & N e.g. {YYYYNNNYYYYYYNNNYY}

 

Is it possible to create a formula that counts the number of Y's in the string.

 

Any help greatly appreciated.

 

Many thanks

IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 08 Oct 2008 at 10:17am
You just have to loop through it and use a counter to keep track of the number of "Y"s.
 
Here is a sample code, but I'm just typing it in off the top of my head and you will probably have to correct a couple syntax errors.
NumberVar NumberYs :=0;
For ThisChar := 1 to Len({database.weeks}) DO
(
   If Mid(database.weeks}, ThisChar, 1) = "Y" Then
     NumberYs := NumberYs + 1;
)
NumberYs;
My Encyclopedia book has three chapters dedicated to teaching you Crystal syntax and how to create formulas with it. You can find out more about my books at Amazon.com or reading the Crystal Reports eBooks online.


Edited by BrianBischof - 08 Oct 2008 at 10:17am
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
Mailman
Newbie
Newbie
Avatar

Joined: 21 Apr 2008
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote Mailman Replybullet Posted: 09 Oct 2008 at 1:18am
Many thanks for this it is very much appreciated.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum