Print Page | Close Window

Count of Characters in Field

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=5363
Printed Date: 30 Apr 2024 at 9:16pm


Topic: Count of Characters in Field
Posted By: EddiRae
Subject: Count of Characters in Field
Date Posted: 29 Jan 2009 at 11:14am
I am trying to get a count of the number of Xs in a field.  I am not sure of the best way to achieve this.
 
If someone could help, I would be greatly appreciative.
 
Eddi Rae



Replies:
Posted By: ricky969
Date Posted: 29 Jan 2009 at 11:26am
if you are trying to get the number of characters in a string, you can use the function Len(str).


Posted By: EddiRae
Date Posted: 29 Jan 2009 at 11:29am

I am only looking for the characters of Xs.  If the field contains XXXOOOX ... I want to count the number of Xs, not all the characters in the field.

Thanks for your input!!


Posted By: JohnT
Date Posted: 29 Jan 2009 at 2:53pm
You could try something like this :
 
local numberVar count:= 0;
local stringVar name := "xxxooox";
Local numberVar strLen:=length(name);
local numberVar I;
for i:=1 to strLen do
    If Mid(name,i,1)= "x"
        then count := count +1;
count

Good luck !


Posted By: EddiRae
Date Posted: 29 Jan 2009 at 3:09pm
That worked perfectly!!!
 
Thank You!!!



Print Page | Close Window