Print Page | Close Window

Split function or easier way?

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=22925
Printed Date: 30 Apr 2024 at 6:54pm


Topic: Split function or easier way?
Posted By: veg_racer
Subject: Split function or easier way?
Date Posted: 09 Feb 2021 at 1:13am
Hi Hive brain,

I have a string field that can be a number of values separated by a comma e.g

CAT, DOG, HORSE
CAT, HORSE
HORSE
HORSE, DOG, HAMSTER
I may also have a Null value here

What I would like to do is count the number of values e.g

CAT, DOG, HORSE = 3
CAT, HORSE = 2
HORSE = 1
HORSE, DOG, HAMSTER = 3
I may also have a Null value here = 0

Thats all I need, I don't really need an array of the values, I just need to know how many values there are. I've started down the "Split" function route but I can't seem to get what I want, is there an easier way?



Replies:
Posted By: kevlray
Date Posted: 16 Feb 2021 at 6:15am
Easier, I do not think so.  It is a parsing problem.  Usually I set up a loop to 'count' each item in the list.  There may be a better solution.  If I have time, I may look into it.


Posted By: Valert16
Date Posted: 17 Feb 2021 at 12:58am
Create a formula using this code (crystal syntax):

If Isnull({Table.StringField}) Then 0 Else Ubound(split({Table.StringField}, ","))


Posted By: veg_racer
Date Posted: 17 Feb 2021 at 1:07am
Seems to work perfectly! Thank you very much!



Print Page | Close Window